使用 Rails 获取单选按钮选择
我正在显示一个单选按钮表,每个按钮对应一个具有唯一 ID 的菜谱。我使用提交标签来准确提交按下的单选按钮,指示选择了哪个食谱。我正在尝试将 id 传递给我的控制器以进行一些查询/表单字段。我在实际传递 id 时遇到了麻烦。有人可以帮我吗,我是 Ruby 新手?谢谢!
<%= form_tag(:action => 'chooseOption') do %>
<%= submit_tag("Show Recipe", :class => 'action show') %>
<%= submit_tag("Delete Recipe", :class => 'action delete') %>
<td><%= radio_button_tag 'recipe', recipe, @recipe == recipe %></td>
<td>recipe.recipe_name</td>
<td>recipe.total_calories</td>
.....all the other fields
</td>
I'm displaying a table of radio buttons, each of which corresponds to a recipe with a unique id. I'm using a submit tag to submit exactly which radio button was pressed, indicating which recipe was selected. I'm trying to pass the id to my controller to make some queries/form fields. I'm having trouble actually passing the id. Can someone help me out, I'm a Ruby newbie? Thanks!
<%= form_tag(:action => 'chooseOption') do %>
<%= submit_tag("Show Recipe", :class => 'action show') %>
<%= submit_tag("Delete Recipe", :class => 'action delete') %>
<td><%= radio_button_tag 'recipe', recipe, @recipe == recipe %></td>
<td>recipe.recipe_name</td>
<td>recipe.total_calories</td>
.....all the other fields
</td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅
http://api.rubyonrails.org/classes /ActionView/Helpers/FormHelper.html#method-i-radio_button
另外
http://guides.rubyonrails.org/form_helpers.html
最后但并非最不重要的一点是,
rails 中单选按钮的标签表格
See
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-radio_button
Also
http://guides.rubyonrails.org/form_helpers.html
And last but not least,
Labels for radio buttons in rails form