Thomas Walther
2012-Jul-26 14:27 UTC
Using the :layout option when calling render @variable
Hey everybody, I wanted to use the :layout option when calling render @variable (where @variable is some ActiveRecord class instance with a corresponding variables/_variable.html.erb partial view), but as far as I know, Rails doesn''t support this. Here''s a quick patch that allows to use the :layout function: In partial_renderer.rb, add the following elsif block: if !block && (layout = @options[:layout]) layout = find_template(layout) elsif !block && (layout = @locals[:layout]) layout = find_template(layout) end I attached a patch so you don''t have to paste the two lines manually. I''m looking forward to your comments, and would love to see this merged in Rails 3.2.7, if possible. Best, Thomas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/03a0JWgAXSEJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Richard Schneeman
2012-Jul-26 15:07 UTC
Re: Using the :layout option when calling render @variable
Thomas, It would be easier for the core team if you could fork the https://github.com/rails/rails repo, make your change in your own repo and then submit a pull request with similar information (why you made the change, why you think others will want it, do the tests pass, did you add tests, etc.). Once the pull request has been made core team members and the general public can comment on your code and the changes on github. -- Richard Schneeman http://heroku.com @schneems (http://twitter.com/schneems) On Thursday, July 26, 2012 at 9:27 AM, Thomas Walther wrote:> Hey everybody, > I wanted to use the :layout option when calling render @variable (where @variable is some ActiveRecord class instance with a corresponding variables/_variable.html.erb partial view), but as far as I know, Rails doesn''t support this. > > Here''s a quick patch that allows to use the :layout function: > > In partial_renderer.rb, add the following elsif block: > if !block && (layout = @options[:layout]) > layout = find_template(layout) > elsif !block && (layout = @locals[:layout]) > layout = find_template(layout) > end > > > I attached a patch so you don''t have to paste the two lines manually. I''m looking forward to your comments, and would love to see this merged in Rails 3.2.7, if possible. > > Best, > Thomas > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/03a0JWgAXSEJ. > To post to this group, send email to rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core+unsubscribe@googlegroups.com). > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > > Attachments: > - rails_use_layout_with_render_variable.patch >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Thomas Walther
2012-Jul-26 16:36 UTC
Re: Using the :layout option when calling render @variable
Hey Richard, thanks for your advice, I will do so. Best, Thomas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/TdyyDN73G3IJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Seemingly Similar Threads
- templates with same name before extension are cached
- Time to fix PartialRenderer#partial_path
- Rails 4.0 has_many_through and fields_for
- Missing template pages/layout only occasionally
- Should i buy Ruby on Rails 3 Essential Training with Kevin Skoglund from Lynda.com