更新操作不保存数据

时间:2011-06-13 21:39:19

标签: ruby-on-rails-3

我无法获取表单文本区域来更新rails 3.0.8应用中的字段。我一直尽力剥离,以缩小错误所在的位置。这是剩下的。

我的表格:

<%= form_for @fb_comments, :remote => true, :html => { :'data-type' => 'html', :id => 'comment' } do |form| %>
    <%= form.text_area :comment %>
    <%= form.submit "Update Comments" %>
<% end %>

我通过mysql为此记录放入注释列的虚拟数据显示,因此当前数据正在将其转换为表单。

控制器:

def update
   fbc = FbComments.find(params[:id])
   fbc.update_attributes(params[:comment])
   ...
end

控制台消息:

Started POST "/fb_comments/1" for 127.0.0.1 at 2011-06-13 17:31:43 -0400
  Processing by FbCommentsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"gLA2A11uVRl/WtIR1p90aSkLoU6b8twotK+B1YNefRk=", "fb_comments"=>{"comment"=>"test test"}, "commit"=>"Update Comments", "id"=>"1"}
  FbComments Load (0.1ms)  SELECT `fb_comments`.* FROM `fb_comments` WHERE `fb_comments`.`id` = 1 LIMIT 1
  SQL (0.1ms)  BEGIN
  SQL (0.1ms)  COMMIT
Rendered text template (0.0ms)
Completed 200 OK in 15ms (Views: 0.6ms | ActiveRecord: 0.3ms)

感谢。

1 个答案:

答案 0 :(得分:1)

您的控制器正在接收fb_comments而不是comment

fbc.update_attributes(params[:fb_comments])

希望这有帮助。