Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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_Simple Form - Fatal编程技术网

Ruby on rails rails单选按钮和向标签添加字符串

Ruby on rails rails单选按钮和向标签添加字符串,ruby-on-rails,ruby,ruby-on-rails-3,simple-form,Ruby On Rails,Ruby,Ruby On Rails 3,Simple Form,我正在尝试使用简单的表单在rails中设置一组单选按钮。选项应该来自地图 在简单的形式中,我看到了:collection符号可以检索一个集合(但只能检索一个数组数组,不能检索散列) 如何显示带有自定义标签的单选按钮集合(理想情况下是从散列中) 这是我到目前为止试过的。我可以将符号与标签的字符串连接起来吗 #Payment.rb OPTIONS = [[14, 19], [21,29], [30,39]] #ideally this would be a hash #new.html.erb

我正在尝试使用简单的表单在rails中设置一组单选按钮。选项应该来自地图

在简单的形式中,我看到了
:collection
符号可以检索一个集合(但只能检索一个数组数组,不能检索散列)

如何显示带有自定义标签的单选按钮集合(理想情况下是从散列中)

这是我到目前为止试过的。我可以将符号与标签的字符串连接起来吗

#Payment.rb
OPTIONS = [[14, 19], [21,29], [30,39]] #ideally this would be a hash 

#new.html.erb
     <%= f.input :duration, 
      :collection =>  [ [14, 19.to_s], [21,29.to_s], [30,39.to_s] ], 
      :label_method => :last.concat(" days"), 
      :value_method => :first, 
      :as => :radio %>
#Payment.rb
选项=[[14,19],[21,29],[30,39]。#理想情况下,这是一个散列
#new.html.erb
[14,19.至],[21,29.至],[30,39.至],
:label_method=>:last.concat(“天”),
:value_method=>:首先,
:as=>:收音机%>

如果我正确理解您的问题,您可以在:label\u方法中使用lambdas。例如:

:label_method => lambda { |a| a.first.to_s + a.last.to_s }