Re: Rails 3, HowTo - Pass a Setting to the Application.html.erb

Robert Pankowecki (rupert)
Sat, 09 Oct 2010 08:32:38 -0000

In my opinion you should have 2 layouts.
* application,
* padding.

The `padding'' layout should be nested inside application and
(according to its name) add some padding :-). Look here about how to
do it in rails 2 and 3:
https://rails.lighthouseapp.com/projects/8994/tickets/5305-rails3-rc-named-yield-should-return-nil-when-content_for-with-that-name-was-not-called

With that you could setup layout per every action.

layout :application
layout :padding, :only => [:new].




The second way of doing this:

Add one more stylesheet in every view that needs padding:

#application.html.erb layout


  <%= yield :head %>


#new.html.erb
content_for(:head) do
  stylesheet_link_tag ''padding''
end

You could abstract it into helper method and use as simple as:
#new.html.erb
<%= padding() %>




Third way is to create helper that would be used this way:

<%= padding do %>
  create your content here
<% end %>


I wouldn''t bother controller with such a minor change in view layer so
I prefere keeping padding in views instead changing layout on the
controller side.

Robert Pankowecki