开发者

Reusing form nested and not nested, how to show submit button

I'm learning rails and building a recipe app.

In my app, a Recipe has a bunch of ingredients.

I've got my ingredients form nested within my recipe form, and I call it with a partial.

Of course, because the form is nested, the

<%= f.submit %>
is in the recipes/_form.html.erb page.

So now I'm trying to edit a single ingredient outside the nested form. I want to use the same form though as it is still an ingredient. So I've created

<% form_for :ingredients, @ingredient, :url{:action =>'update', :id=>@ingredient.id} do |f| %>
      <% render :partial => 'form', :locals => {:f=>f} %>
     <%= f.submit %>
<% end %>

for some reason, this results in only the submit button being shown.

If I put the submit button inside the partial, it would show u开发者_如何学Gop within the recipe form which just isn't right.


You are missing the = operator while trying to render the partial, it should be:

<%= render :partial => 'form', :locals => { :f => f } %>

It should work, hope it helps you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜