Ruby on rails 如何使用助手方法填充Rails中的单选按钮集合?
我试图用单选按钮集合(?)填充表单:Ruby on rails 如何使用助手方法填充Rails中的单选按钮集合?,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2,radio-button,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.2,Radio Button,我试图用单选按钮集合(?)填充表单: # _fields.html.erb <%= f.label :invoice_type %><br/> <%= radio_tags_for_select(f.object.invoice_types) %> # application_helper.rb def radio_tags_for_select(types) types_html = types.map do |type| co
# _fields.html.erb
<%= f.label :invoice_type %><br/>
<%= radio_tags_for_select(f.object.invoice_types) %>
# application_helper.rb
def radio_tags_for_select(types)
types_html = types.map do |type|
content_tag :span, :class => "radio_option" do
radio_button(:invoice_types, type, type) + type
end
end
safe_join(types_html)
end
#u fields.html.erb
#应用程序\u helper.rb
def收音机标签用于选择(类型)
types_html=types.map do | type|
content\u标签:span,:class=>“radio\u option”do
单选按钮(:发票类型,类型,类型)+类型
结束
结束
安全连接(类型\u html)
结束
这一行的语法似乎不正确:单选按钮(:invoice\u types,type,type)+type
,因为表单被显示,但没有保存到数据库中
有人能帮忙吗
谢谢…我认为您必须将原始字符串转义为html:
content_tag :span, :class => "radio_option" do
raw( radio_button(:invoice_types, type, type) + type )
end
这就是我的结局:
def radio_tags_for_select(types, f)
types_html = types.map do |type|
content_tag :span, :class => "radio_option" do
f.radio_button(:invoice_type, type) + localize_address_type(type)
end
end
safe_join(types_html)
end
似乎我以前忘记传递对象f
请让我知道这个代码是否可以简化。我愿意接受建议。请检查您的参数以获得更好的想法。谢谢,但实际上
safe\u join(types\u html)
做得很好。