我想在编辑表单中更新Transaction
对象的status
属性。状态应该是一个下拉列表,我可以选择与实际PATCH到对象的整数值相关的文本值。
换句话说,我有一个看起来像这样的变量:
@statuscodes = [
{ "Working" => 1 },
{ "In progress" => 2 },
{ "Cancelled: No response from borrower" => 3 },
{ "Cancelled: No response from lender" => 4 },
{ "Cancelled: Time period too long" => 5 },
...
]
根据文档和其他一些SO帖子,我已经尝试了f.select
和f.collection_select
我认为正确的语法。显然不是,我已经为后面的每一个打印了错误。对我做错了什么的想法?
<%= f.select :transaction, :status, options_for_select(@statuscodes), {include_blank: true} %>
<!-- undefined method `merge' for #<ActiveSupport::SafeBuffer:0x007fd9da299300> -->
<%= f.collection_select :transaction, :status, @statuscodes, :last, :first, {include_blank: true} %>
<!-- undefined method `merge' for :first:Symbol -->
<%= f.select :transaction, :status, @statuscodes, {include_blank: true} %>
<!-- undefined method `merge' for #<Array:0x007fd9e1381b30> -->
答案 0 :(得分:1)
它应该是这样的:
<%= f.collection_select :status, @statuscodes[0], :last, :first, {include_blank: true} %>
请注意,第二个参数应该是hash
或array of objects
,可以调用第3和第4个参数中提供的方法。