route.rb match "/:layout" => "company@index" in application_controller I have: before_filter :authenticate_user! rescue_from DeviseLdapAuthenticatable::LdapException do |exception| render :text => exception, :status => 500 end protect_from_forgery before_filter :set_layout layout :specify_layout def specify_layout if @current_layout == :intra "intranet" elsif @current_layout == :inter "internet" else "application" end end def set_layout if params[:layout] == "intraOp" session[:current_layout] = :intra elsif params[:layout] == "interOp" session[:current_layout] = :inter else session[:current_layout] = nil end @current_layout = session[:current_layout] end end in another controller I have: skip_filter :authenticate_user!, :only => [:index, :show] unless @current_layout.nil? unless condition seem does not work. What I am missing? -- 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 Sat, Feb 11, 2012 at 9:46 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> route.rb > > match "/:layout" => "company@index" > > in application_controller I have: > > before_filter :authenticate_user! > rescue_from DeviseLdapAuthenticatable::LdapException do |exception| > render :text => exception, :status => 500 > end > protect_from_forgery > before_filter :set_layout > > layout :specify_layout > > def specify_layout > if @current_layout == :intra > "intranet" > elsif @current_layout == :inter > "internet" > else > "application" > end > end > > def set_layout > if params[:layout] == "intraOp" > session[:current_layout] = :intra > elsif params[:layout] == "interOp" > session[:current_layout] = :inter > else > session[:current_layout] = nil > end > @current_layout = session[:current_layout] > end > end > > in another controller I have: > > skip_filter :authenticate_user!, :only => [:index, :show] unless > @current_layout.nil? > > unless condition seem does not work. > What I am missing? > >Maybe it could be :unless => @current_layout.nil? instead of unless @current_layout.nil?> -- > 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. > >-- 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.
> skip_filter :authenticate_user!, :only => [:index, :show] unless > @current_layout.nil?I''m guessing that the unless statement is being parsed as an argument to skip_filter. Try using parentheses like this: skip_filter(:authenticate_user!, :only => [:index, :show]) unless @current_layout.nil? Mike -- 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 12 February 2012 02:32, Mike Kim <fourcatrails-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> skip_filter :authenticate_user!, :only => [:index, :show] unless >> @current_layout.nil? > > I''m guessing that the unless statement is being parsed as an argument > to skip_filter. Try using parentheses like this: > > skip_filter(:authenticate_user!, :only => [:index, :show]) unless > @current_layout.nil? >I''ve tried in both manners but nothing :-( -- 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 11 February 2012 23:46, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> route.rb > > match "/:layout" => "company@index" > > in application_controller I have: > > before_filter :authenticate_user! > rescue_from DeviseLdapAuthenticatable::LdapException do |exception| > render :text => exception, :status => 500 > end > protect_from_forgery > before_filter :set_layout > > layout :specify_layout > > def specify_layout > if @current_layout == :intra > "intranet" > elsif @current_layout == :inter > "internet" > else > "application" > end > end > > def set_layout > if params[:layout] == "intraOp" > session[:current_layout] = :intra > elsif params[:layout] == "interOp" > session[:current_layout] = :inter > else > session[:current_layout] = nil > end > @current_layout = session[:current_layout] > end > end > > in another controller I have: > > skip_filter :authenticate_user!, :only => [:index, :show] unless > @current_layout.nil? > > unless condition seem does not work. > What I am missing?Is it possible that your before_filter .. unless test is being run before set_layout is called? You could display some debug output to find out. 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 12 February 2012 12:14, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 February 2012 23:46, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> route.rb >> >> match "/:layout" => "company@index" >> >> in application_controller I have: >> >> before_filter :authenticate_user! >> rescue_from DeviseLdapAuthenticatable::LdapException do |exception| >> render :text => exception, :status => 500 >> end >> protect_from_forgery >> before_filter :set_layout >> >> layout :specify_layout >> >> def specify_layout >> if @current_layout == :intra >> "intranet" >> elsif @current_layout == :inter >> "internet" >> else >> "application" >> end >> end >> >> def set_layout >> if params[:layout] == "intraOp" >> session[:current_layout] = :intra >> elsif params[:layout] == "interOp" >> session[:current_layout] = :inter >> else >> session[:current_layout] = nil >> end >> @current_layout = session[:current_layout] >> end >> end >> >> in another controller I have: >> >> skip_filter :authenticate_user!, :only => [:index, :show] unless >> @current_layout.nil? >> >> unless condition seem does not work. >> What I am missing? > > Is it possible that your before_filter .. unless test is being run > before set_layout is called? You could display some debug output to > find out.Sorry for my ignorance, how can I display some debug? -- 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 12 February 2012 11:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 February 2012 12:14, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 11 February 2012 23:46, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> route.rb >>> >>> match "/:layout" => "company@index" >>> >>> in application_controller I have: >>> >>> before_filter :authenticate_user! >>> rescue_from DeviseLdapAuthenticatable::LdapException do |exception| >>> render :text => exception, :status => 500 >>> end >>> protect_from_forgery >>> before_filter :set_layout >>> >>> layout :specify_layout >>> >>> def specify_layout >>> if @current_layout == :intra >>> "intranet" >>> elsif @current_layout == :inter >>> "internet" >>> else >>> "application" >>> end >>> end >>> >>> def set_layout >>> if params[:layout] == "intraOp" >>> session[:current_layout] = :intra >>> elsif params[:layout] == "interOp" >>> session[:current_layout] = :inter >>> else >>> session[:current_layout] = nil >>> end >>> @current_layout = session[:current_layout] >>> end >>> end >>> >>> in another controller I have: >>> >>> skip_filter :authenticate_user!, :only => [:index, :show] unless >>> @current_layout.nil? >>> >>> unless condition seem does not work. >>> What I am missing? >> >> Is it possible that your before_filter .. unless test is being run >> before set_layout is called? You could display some debug output to >> find out. > > Sorry for my ignorance, how can I display some debug?Have a look at the Rails Guide on Debugging, it shows several techniques. 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.
> skip_filter :authenticate_user!, :only => [:index, :show] unless > @current_layout.nil? > > unless condition seem does not work. > What I am missing?The unless will run at class-definition time, not on each request. It also runs in the context of the class, not the instance - so @current_layout will *always* be nil. To do conditional activation of callbacks, try the :if or :unless options. These take either a symbol representing a method or a proc. --Matt Jones -- 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 12 February 2012 18:59, Matt Jones <al2o3cr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >> skip_filter :authenticate_user!, :only => [:index, :show] unless >> @current_layout.nil? >> >> unless condition seem does not work. >> What I am missing? > > The unless will run at class-definition time, not on each request. It > also runs in the context of the class, not the instance - so > @current_layout will *always* be nil. > > To do conditional activation of callbacks, try the :if or :unless > options. These take either a symbol representing a method or a proc.I''ve tried skip_filter :authenticate_user!, :only => [:index, :show] :unless => lambda {@current_layout.nil?} But does not work. -- 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 12 February 2012 12:14, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 February 2012 23:46, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> route.rb >> >> match "/:layout" => "company@index" >> >> in application_controller I have: >> >> before_filter :authenticate_user! >> rescue_from DeviseLdapAuthenticatable::LdapException do |exception| >> render :text => exception, :status => 500 >> end >> protect_from_forgery >> before_filter :set_layout >> >> layout :specify_layout >> >> def specify_layout >> if @current_layout == :intra >> "intranet" >> elsif @current_layout == :inter >> "internet" >> else >> "application" >> end >> end >> >> def set_layout >> if params[:layout] == "intraOp" >> session[:current_layout] = :intra >> elsif params[:layout] == "interOp" >> session[:current_layout] = :inter >> else >> session[:current_layout] = nil >> end >> @current_layout = session[:current_layout] >> end >> end >> >> in another controller I have: >> >> skip_filter :authenticate_user!, :only => [:index, :show] unless >> @current_layout.nil? >> >> unless condition seem does not work. >> What I am missing? > > Is it possible that your before_filter .. unless test is being run > before set_layout is called? You could display some debug output to > find out.It seems so, I''ve tried before_filter :set_layout, :authenticate_user! but it seems that @current_layout is always nil when skip_filter is run, it is strange to me because set_layout is run before authenticate_user I think. -- 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 12 February 2012 19:34, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 February 2012 12:14, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 11 February 2012 23:46, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> route.rb >>> >>> match "/:layout" => "company@index" >>> >>> in application_controller I have: >>> >>> before_filter :authenticate_user! >>> rescue_from DeviseLdapAuthenticatable::LdapException do |exception| >>> render :text => exception, :status => 500 >>> end >>> protect_from_forgery >>> before_filter :set_layout >>> >>> layout :specify_layout >>> >>> def specify_layout >>> if @current_layout == :intra >>> "intranet" >>> elsif @current_layout == :inter >>> "internet" >>> else >>> "application" >>> end >>> end >>> >>> def set_layout >>> if params[:layout] == "intraOp" >>> session[:current_layout] = :intra >>> elsif params[:layout] == "interOp" >>> session[:current_layout] = :inter >>> else >>> session[:current_layout] = nil >>> end >>> @current_layout = session[:current_layout] >>> end >>> end >>> >>> in another controller I have: >>> >>> skip_filter :authenticate_user!, :only => [:index, :show] unless >>> @current_layout.nil? >>> >>> unless condition seem does not work. >>> What I am missing? >> >> Is it possible that your before_filter .. unless test is being run >> before set_layout is called? You could display some debug output to >> find out. > > It seems so, I''ve tried before_filter :set_layout, :authenticate_user! > but it seems that @current_layout is always nil when skip_filter is > run, it is strange to me because set_layout is run before > authenticate_user I think.Well put in some debug and prove it one way or the other. 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.
> Well put in some debug and prove it one way or the other.Then: application_controller: before_filter :set_layout, :authenticate_user! #(authenticate_user is from devise gem) def set_layout if params[:current_layout] == "intraOp" session[:current_layout] = :intra elsif params[:current_layout] == "interOp" session[:current_layout] = :inter else session[:current_layout] = nil end @current_layout = session[:current_layout] end end companies_controller: skip_filter :authenticate_user!, :only => [:index, :show], :unless => lambda {@current_layout.nil?} def index debugger .... . .... end rails s --debugger (rdb:2) instance_variables [:@_params, :@_response_body, :@_response, :@_action_name, :@_action_has_layout, :@_env, :@current_layout, :@_request, :@_config, :@_lookup_context, :@_prefixes, :@_headers, :@_routes, :@_status] (rdb:2) @current_layout nil @current_layout is nil but authenticate_user! in companies_controller is skipped despite :unless => lambda {@current_layout.nil?} -- 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.
> @current_layout is nil but authenticate_user! in companies_controller > is skipped despite :unless => lambda {@current_layout.nil?}Perhaps skip_filter does not accept conditionals unless or if? -- 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.
Try this: before_filter :authenticate_user! *return true if @current_layout.nil?* rescue_from DeviseLdapAuthenticatable::LdapException do |exception| render :text => exception, :status => 500 end And then: skip_filter :authenticate_user!, :only => [:index, :show] But, I don''t know if the condition should be: *return true if @current_layout.nil?* *or* *return true unless @current_layout.nil?* * * because I didn''t understand very well what are you doing. Regards, Everaldo On Sun, Feb 12, 2012 at 8:51 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > @current_layout is nil but authenticate_user! in companies_controller > > is skipped despite :unless => lambda {@current_layout.nil?} > > Perhaps skip_filter does not accept conditionals unless or if? > > -- > 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. > >-- 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 13 February 2012 03:11, Everaldo Gomes <everaldo.gomes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > because I didn''t understand very well what are you doing.I''m trying to do: in route.rb I have: match "/:layout" => "companies#index" Then when I call localhost/intraOp ther params[:layout] is "intraOp", when I call localhost/interOp the params[:layout] is "interOp". In application_controller I set: before_filter :set_layout, :authenticate_user! #(authenticate_user is from devise gem) def set_layout if params[:current_layout] == "intraOp" session[:current_layout] = :intra elsif params[:current_layout] == "interOp" session[:current_layout] = :inter else session[:current_layout] = nil end @current_layout = session[:current_layout] end end Then I have @current_layout set to "intraOp" or "interOp", if neither intraOp or interOp is set then @current_layout is nil. In application_controller I have also before_filter :set_layout, :authenticate_user!. In companies_controller I''ve set skip_filter :authenticate_user!, only[:index, :show] but I want not to skip if @current_layout is nil. -- 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 12 February 2012 22:51, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> @current_layout is nil but authenticate_user! in companies_controller >> is skipped despite :unless => lambda {@current_layout.nil?} > > Perhaps skip_filter does not accept conditionals unless or if?I think you are right, I don''t see it in the docs. Possibly a better way anyway, which might make more readable code, would be to not call authenticate directly from the filter but to call a method you provide which checks the params and calls authenticate if necessary. Then all the logic is in one place. 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.