Render a "new" form in another view

13 views
Skip to first unread message

Linus Pettersson

unread,
Jul 25, 2011, 1:25:35 PM7/25/11
to rubyonra...@googlegroups.com
Hi!

I have a list where you can add items, where Items are nested inside Lists.

So, now I want to render my form partial to create new items in the Lists show view. I want to be able to add items to the list without leaving the list through a link.

My _form partial looks like this
<%= semantic_form_for [@item.list, @item] do |f| %>
  <%= f.inputs "Item" do %>
    <%= f.input :title %>
    <%= f.input :amount %>
    <%= f.input :unit %>
  <% end %>
   <%= f.buttons %>
<% end %>

I have tried to just do  <%= render 'items/form' %> which doesn't work. I guess I have to send populate the @item variable when rendering the template.
Also, I'm not sure how the form will know this is a new action and not an edit.

Walter Lee Davis

unread,
Jul 25, 2011, 2:10:32 PM7/25/11
to rubyonra...@googlegroups.com

It will know because the @item won't have an ID -- @item.new_record?
will return true.

Walter

Reply all
Reply to author
Forward
0 new messages