【发布时间】:2012-02-19 10:39:31
【问题描述】:
这里有点 Rails 新手,所以请多多包涵。
我试图通过首先列出每个条目的单选按钮,然后将条目的字段仅作为文本列出来在表格中列出一堆条目。
它工作正常,它也以我想要的方式显示。但是,问题是每当我使用我的按钮时。这个想法是让用户选择一个单选按钮来选择一个特定的配方,然后单击页面顶部的通用添加、编辑、删除按钮之一,以对所选配方执行相应的操作。
到目前为止,这是我的代码:
<!--Action buttons at the top of page, supposed to communicate with the radio buttons -->
<%= link_to("Show", {:action => 'show', :id => recipe.id}, :class => 'action show') %>
<%= link_to("Edit", {:action => 'edit', :id => recipe.id}, :class => 'action edit') %>
<%= link_to("Delete", {:action => 'delete', :id => recipe.id}, :class => 'action delete') %>
<% @recipes.each do |recipe| %>
<tr>
<td><%= radio_button_tag 'recipe', recipe, @recipe == recipe %></td>
<td><%= recipe.total_calories %></td>
<td><%=........15 more fields
</tr>`
<% end unless @recipes.nil? %>
未定义的局部变量或方法“recipe”向我抛出了错误。我明白为什么会出现错误; Ruby 并不确切知道用户通过单选按钮选择了哪个配方。有人可以告诉我如何让单选按钮与操作按钮进行通信吗?
【问题讨论】:
标签: html ruby ruby-on-rails-3 radio-button