Hi, I''m trying to pinpoint what the issue might be here. In a controller that has the appropriate layout (layouts/controller.html.erb), if I try to override the layout to the ''application'' layout only for certain actions, those actions do get rendered with the application layout... Like this: layout ''application'', :only => :new The ''new'' action renders fine, but now the other actions don''t render at all! No error or anything, just an empty response. I''ve tried renaming the layout files to see if an error shows up, and no error (so no layout is being picked up). On my views I have content_for, so since nothing is yielding those contents, nothing shows up. If I put something outside a content_for, it does show up (without a layout of course). If I explicitly render the layout on the action, it works, like so: render :layout => ''somelayout'' So what''s the deal here? Thanks in advance! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Englert
2008-Nov-20 03:53 UTC
Re: Overriding layout causes empty response with content_for
I would try to explicitly specify the layout for the other actions. If you read the docs, you can sort of infer that no layout will be applied if you explicitly apply a layout to some actions: http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html "This will assign "weblog_standard" as the WeblogController''s layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000301>except for the rss action, which will not wrap a layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000301>around the rendered view." Not sure that''s the right answer -- just offering. jim jim-rants.com On Wed, Nov 19, 2008 at 10:44 PM, Ivan V. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Hi, > > I''m trying to pinpoint what the issue might be here. In a controller > that has the appropriate layout (layouts/controller.html.erb), if I try > to override the layout to the ''application'' layout only for certain > actions, those actions do get rendered with the application layout... > Like this: > > layout ''application'', :only => :new > > The ''new'' action renders fine, but now the other actions don''t render at > all! > > No error or anything, just an empty response. I''ve tried renaming the > layout files to see if an error shows up, and no error (so no layout is > being picked up). > > On my views I have content_for, so since nothing is yielding those > contents, nothing shows up. If I put something outside a content_for, it > does show up (without a layout of course). > > If I explicitly render the layout on the action, it works, like so: > > render :layout => ''somelayout'' > > So what''s the deal here? > > Thanks in advance! > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ivan V.
2008-Nov-20 04:11 UTC
Re: Overriding layout causes empty response with content_for
After unsuccessfully trying an after_filter to do the render, I did found out that it is rendering with render_with_no_layout... I was trying to avoid having an explicit render on every action, and now with your comment as I re-read the docs, I think I found an oh-so-ugly solution: layout proc{ |controller| [ ''new'', ''etc'' ].include?(controller.action_name) ? ''application'' : ''otherlayout'' } Thanks James Englert wrote:> I would try to explicitly specify the layout for the other actions. If > you > read the docs, you can sort of infer that no layout will be applied if > you > explicitly apply a layout to some actions: > http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html > > "This will assign "weblog_standard" as the WeblogController''s > layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000301>except > for the > rss action, which will not wrap a > layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000301>around > the rendered view." > > Not sure that''s the right answer -- just offering. > > jim > jim-rants.com > > On Wed, Nov 19, 2008 at 10:44 PM, Ivan V.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian Ploetz
2008-Nov-20 04:16 UTC
Re: Overriding layout causes empty response with content_for
Ivan V. wrote:> Hi, > > I''m trying to pinpoint what the issue might be here. In a controller > that has the appropriate layout (layouts/controller.html.erb), if I try > to override the layout to the ''application'' layout only for certain > actions, those actions do get rendered with the application layout... > Like this: > > layout ''application'', :only => :new > > The ''new'' action renders fine, but now the other actions don''t render at > all! > > No error or anything, just an empty response. I''ve tried renaming the > layout files to see if an error shows up, and no error (so no layout is > being picked up). > > On my views I have content_for, so since nothing is yielding those > contents, nothing shows up. If I put something outside a content_for, it > does show up (without a layout of course). > > If I explicitly render the layout on the action, it works, like so: > > render :layout => ''somelayout'' > > So what''s the deal here? > > Thanks in advance!Try this instead: specify a default controller-wide layout, and then action-specific layouts defined within the action itself via render. class MyController < ActionController::Base layout "default_layout" def foo render :action => "foo", :layout => "foo_layout" end end http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000301 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
THEBIGO
2008-Nov-20 05:57 UTC
Re: Overriding layout causes empty response with content_for
Hello - have you tried looking at Ryan Bates raiscasts - he has a couple on layouts that might help http://railscasts.com/tags/4?page=4 Owen On Nov 19, 8:16 pm, Brian Ploetz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ivan V. wrote: > > Hi, > > > I''m trying to pinpoint what the issue might be here. In a controller > > that has the appropriate layout (layouts/controller.html.erb), if I try > > to override the layout to the ''application'' layout only for certain > > actions, those actions do get rendered with the application layout... > > Like this: > > > layout ''application'', :only => :new > > > The ''new'' action renders fine, but now the other actions don''t render at > > all! > > > No error or anything, just an empty response. I''ve tried renaming the > > layout files to see if an error shows up, and no error (so no layout is > > being picked up). > > > On my views I have content_for, so since nothing is yielding those > > contents, nothing shows up. If I put something outside a content_for, it > > does show up (without a layout of course). > > > If I explicitly render the layout on the action, it works, like so: > > > render :layout => ''somelayout'' > > > So what''s the deal here? > > > Thanks in advance! > > Try this instead: specify a default controller-wide layout, and then > action-specific layouts defined within the action itself via render. > > class MyController < ActionController::Base > layout "default_layout" > > def foo > render :action => "foo", :layout => "foo_layout" > end > end > > http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho... > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---