重用嵌套和不嵌套的表单,如何显示提交按钮
我正在学习 Rails 并构建一个食谱应用程序。
在我的应用程序中,食谱有很多成分。
我的配料表嵌套在我的食谱表中,我用部分来称呼它。
当然,由于表单是嵌套的,
<%= f.submit %>is in the recipes/_form.html.erb page.
所以现在我正在尝试编辑嵌套表单之外的单个成分。我想使用相同的形式,因为它仍然是一种成分。所以我
<% form_for :ingredients, @ingredient, :url{:action =>'update', :id=>@ingredient.id} do |f| %> <% render :partial => 'form', :locals => {:f=>f} %> <%= f.submit %> <% end %>
出于某种原因创建了这个结果,结果只显示提交按钮。
如果我将提交按钮放在部分中,它将显示在食谱表单中,这是不正确的。
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 up within the recipe form which just isn't right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在尝试渲染部分时缺少
=
运算符,它应该是:它应该可以工作,希望它对您有帮助!
You are missing the
=
operator while trying to render the partial, it should be:It should work, hope it helps you!