Module: SocialStream::Controllers::Helpers::InstanceMethods
- Defined in:
- lib/social_stream/controllers/helpers.rb
Instance Method Summary collapse
-
#current_ability ⇒ Object
Override Cancan#current_ability method to use #current_subject.
- #current_actor ⇒ Object
-
#current_subject ⇒ Object
Current subject represented by the user.
-
#current_subject=(instance) ⇒ Object
Set represented subject.
-
#profile_subject ⇒ Object
Returns the subject that is in the path, or the #current_subject if some User is logged in.
-
#profile_subject! ⇒ Object
Go to sign in page if #profile_subject is blank.
-
#profile_subject_is_current? ⇒ Boolean
A User must be logged in and is equal to #profile_subject.
Instance Method Details
#current_ability ⇒ Object
Override Cancan#current_ability method to use #current_subject
89 90 91 92 |
# File 'lib/social_stream/controllers/helpers.rb', line 89 def current_ability @current_ability ||= Ability.new(current_subject) end |
#current_actor ⇒ Object
50 51 52 |
# File 'lib/social_stream/controllers/helpers.rb', line 50 def current_actor current_subject.actor end |
#current_subject ⇒ Object
Current subject represented by the user. Defaults to the own user
35 36 37 38 39 40 |
# File 'lib/social_stream/controllers/helpers.rb', line 35 def current_subject @current_subject ||= current_subject_from_params || current_subject_from_session || current_user end |
#current_subject=(instance) ⇒ Object
Set represented subject
43 44 45 46 47 48 |
# File 'lib/social_stream/controllers/helpers.rb', line 43 def current_subject= instance session[:subject_type] = instance.class.to_s session[:subject_id] = instance.id @current_subject = instance end |
#profile_subject ⇒ Object
Returns the subject that is in the path, or the #current_subject if some User is logged in.
Requirements: the controller must inherit from InheritedResources::Base
and the method ClassMethods#belongs_to_subjects must be called
class PostsController < InheritedResources::Base
belongs_to_subjects :optional => true
end
# /users/demo/posts
profile_subject #=> User demo
# /groups/test/posts
profile_subject #=> Group test
# /posts
profile_subject #=> current_subject
74 75 76 |
# File 'lib/social_stream/controllers/helpers.rb', line 74 def profile_subject @profile_subject ||= association_chain[-1] || current_subject end |
#profile_subject! ⇒ Object
Go to sign in page if #profile_subject is blank
79 80 81 |
# File 'lib/social_stream/controllers/helpers.rb', line 79 def profile_subject! @profile_subject ||= association_chain[-1] || warden.authenticate! end |
#profile_subject_is_current? ⇒ Boolean
A User must be logged in and is equal to #profile_subject
84 85 86 |
# File 'lib/social_stream/controllers/helpers.rb', line 84 def profile_subject_is_current? user_signed_in? && profile_subject == current_subject end |