【发布时间】:2014-01-17 17:29:43
【问题描述】:
我的控制器方法中有以下内容:
@comment = Comment.where(:reviewed_at == nil).first
那么,在我看来,我有这个:
<b><%= @comment.comment %></b>
<br>
<br>
<%= simple_form_for :phrase do |f| %>
<%= f.input :phrase, label: 'Phrase you would like to add:' %>
<br>
<%= f.input :emotion, collection: [[true, 'Positive'], [false, 'Negative']], as: :radio_buttons, label: 'Emotion', label_method: :last %>
<br>
<%= f.input :category, collection: @categories, as: :radio_buttons, label: 'Categories', label_method: :last %>
<br>
<%= f.button :submit, 'Add to Dictionary' %>
<% end %>
当按下:submit 按钮时,我还需要将@comment 传递回我的控制器,或者以某种方式从我的控制器访问@comment。我尝试使用-
f.hidden :comment, :value => @comment
在我的simple_form_for block 内,但没有骰子。我知道我可以通过查询数据库再次查看评论,但我觉得这不是正确的方法。如何将我的变量传递给视图,然后再传回控制器?
【问题讨论】:
标签: ruby-on-rails view controller