重用嵌套和不嵌套的表单,如何显示提交按钮

发布于 2024-09-25 03:33:25 字数 555 浏览 0 评论 0原文

我正在学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2024-10-02 03:33:25

您在尝试渲染部分时缺少 = 运算符,它应该是:

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

它应该可以工作,希望它对您有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文