In my header, users can add an “item” via a form. I want this option to be available on each page, so I have in my header :
<%= form_for(@item) do |f| %>
<div>
<div class="title"><%= f.label :name, "Name" %></div>
<div class="champ"><%= f.text_field :name %></div>
</div>
<div>
<%= f.submit "add this item" %>
</div>
<% end %>
But it forces me to add this in each controller :
def action
@item = Item.new
end
How can I avoid it ? Using Application controller ?
Thanks !
Define a method in application controller and use
before_filter.initialize_item method will be executed on each request now.