Rails3 form_for hide_field 未定义方法“合并”
我尝试在 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 技术交流群。

如果您可以粘贴错误消息本身以及跟踪的相关行,它可以帮助我们。现在,我唯一看到的是
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 withHash
objects. Maybe it can point you in the right directionEDIT Ok I get it. You have to write
f.hidden_field :commodity_id, :value => @commodity.id
.