Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用助手方法填充Rails中的单选按钮集合?_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 3.2_Radio Button - Fatal编程技术网

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)
做得很好。