In my application_controller I have: before_filter :set_default_role layout :specify_layout private def specify_layout if @current_role == :intra_guest "intranet" elsif @current_role == :inter_guest "internet" else #(devise_controller? || user_signed_in?) "application" end end def set_default_role if request.path == "/intraOp" @current_role = :intra_guest elsif request.path == "/interOp" @current_role = :inter_guest else @current_role = current_user.try(:role) end end When I call http://mysite/intraOp....@current_role is set to :intra_guest but if I click to a link, say http://mysite/other, the @current_role in not :intra_guest anymore because the path is not /intraOp and before_filter is run every time before an action. I think the solution is to run set_default_role only one at application start and not before every controller action. Advices? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 November 2011 12:14, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In my application_controller I have: > > before_filter :set_default_role > > layout :specify_layout > > private > def specify_layout > if @current_role == :intra_guest > "intranet" > elsif @current_role == :inter_guest > "internet" > else > #(devise_controller? || user_signed_in?) > "application" > end > end > > def set_default_role > if request.path == "/intraOp" > @current_role = :intra_guest > elsif request.path == "/interOp" > @current_role = :inter_guest > else > @current_role = current_user.try(:role) > end > end > > When I call http://mysite/intraOp....@current_role is set to > :intra_guest but if I click to a link, say http://mysite/other, the > @current_role in not :intra_guest anymore because the path is not > /intraOp and before_filter is run every time before an action. > I think the solution is to run set_default_role only one at > application start and not before every controller action. > Advices?If you always want it :intra_guest then why have you got the logic in set_default_role why not just set it to that? You say that you want to set it once at application start, remember that the application will server multiple users one after the other without restarting, so all users would get the same value. If you are trying to do it based on which url a user goes to *first* then save the value in the session for later use by that user. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 November 2011 14:29, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > If you always want it :intra_guest then why have you got the logic in > set_default_role why not just set it to that?The user may or not login to the application, if the user wants to manage the application then it must be logged in and a role is assigned, say admin, if it wants only see a list of products, for example, then it must not to be logged in and I assign a default role, say guest. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 November 2011 14:42, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 23 November 2011 14:29, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> >> If you always want it :intra_guest then why have you got the logic in >> set_default_role why not just set it to that? > > The user may or not login to the application, if the user wants to > manage the application then it must be logged in and a role is > assigned, say admin, if it wants only see a list of products, for > example, then it must not to be logged in and I assign a default role, > say guest.So how could you set it once at application start when you need different values for different users? Application Start is when the server is started. It may not be restarted for months. There is not one instance of the application for each user. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.