Rails3 form_for hide_field 未定义方法“合并”

发布于 01-05 16:41 字数 671 浏览 5 评论 0原文

我尝试在 form_for 中放置隐藏字段,但由于 ActionView 帮助程序错误而在黄瓜中崩溃。由于我还没有深入研究源代码,所以关于 FixNum 的一些事情我也没有注意到。我的prices_controller显示了这个:

 @price = Price.new
  @commodity = Commodity.find(params[:id])

我想用这个hidden_​​field建立价格和商品之间的链接:

 <%= form_for (@price), :url => prices_path  do |f| %>
  <% f.hidden_field :commodity_id, @commodity.id %>
 .
 .
 <div class="actions">
 <%= f.submit "Submit" %>
   </div>

查看form_for api,上面的应该可以工作。阅读 stackoveflow 上的其他回复,我已将 hide_field 放在表单中自己的 div 中,添加了一个 Hidden_​​field_tag ,并将其放置在提交行之前的 actions div 中。看看合并消息,我猜它不喜欢该行的某些内容,但对我来说似乎没问题。商品_id字段为匹配字段,sam

My attempt to place a hidden_field within a form_for is crashing within cucumber on an ActionView helper error. Something also about FixNum which escapes me since I haven't dug through the source code. My prices_controller shows this:

 @price = Price.new
  @commodity = Commodity.find(params[:id])

I want to make the link between price and commodity with this hidden_field:

 <%= form_for (@price), :url => prices_path  do |f| %>
  <% f.hidden_field :commodity_id, @commodity.id %>
 .
 .
 <div class="actions">
 <%= f.submit "Submit" %>
   </div>

Looked at the form_for api and the above should work. Reading other replies on stackoveflow, I have put the hidden_field in its own div within the form, added a Hidden_field_tag, and placed it within the actions div before the submit line. Looking at the merge msg, I guess it doesn't like something about the line, but it appears OK to me. The commodity_id field is the match field, sam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

一场春暖2025-01-12 16:41:21

如果您可以粘贴错误消息本身以及跟踪的相关行,它可以帮助我们。现在,我唯一看到的是 f.hidden_​​field 之前的 ERB 标记应该是 <%=,而且我不确定它,因为我不'不要使用 ERB。就其价值而言,合并通常与 Hash 对象一起使用。也许它可以为您指明正确的方向

编辑好的我明白了。您必须编写 f.hidden_​​field :commodity_id, :value =>; @commodity.id

If you could paste the error message itself, and the relevant lines of the trace, it could help us. Right now, the only thing I see is that the ERB tag before f.hidden_field should be <%=, and I'm not sure about it since I don't use ERB. For what it's worth, merge is usually used with Hash objects. Maybe it can point you in the right direction

EDIT Ok I get it. You have to write f.hidden_field :commodity_id, :value => @commodity.id.

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