rails表单输入文本未保存,点击提交后所有字段均为空白

时间:2014-03-30 08:40:53

标签: ruby-on-rails forms scaffolding

我有一个rails scaffold评论有不同的字段(文本输入),如艺术家,日期,地点等。在表单页面上,我刚刚为用户创建了一个新的控制器/模型后,我的输入都没有被保存。我可以使用表单创建包含电子邮件和密码的新用户并将其保存,但是当我尝试创建新的评论时,所有信息在我点击提交后都是空白的。是什么导致这个?创建用户后,我没有修改评论控制器或模型的任何代码。现在有2个迁移文件,一个用于评论,一个用于用户,但我也没有修改。我确实修改了application_controller.rb文件以检测用户是否已登录,但我认为这不会导致问题?

我尝试做rake db:drop和rake db:create all并再次迁移,但仍然出现问题。感谢任何帮助,谢谢。

当我点击提交时,这是我得到的错误:

> Started POST "/reviews" for 127.0.0.1 at 2014-03-30 04:50:13 -0400
Processing by ReviewsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"YzL5s5e+nT/2U3zoYtrmAT443qIn2fUMjx/MAmGoyTk=", "review"=>{"artist"=>"testArtist", "venue"=>"testVenue", "date"=>"3/30/2014", "genre"=>"Rock", "sound"=>"3", "stagePresence"=>"4", "songSelection"=>"5", "overallRating"=>"2", "comments"=>"testComment"}, "commit"=>"Create Review"}
WARNING: Can't mass-assign protected attributes for Review: artist, venue, date, genre, sound, stagePresence, songSelection, overallRating, comments
    app/controllers/reviews_controller.rb:27:in `create'
   (0.2ms)  BEGIN
  SQL (38.2ms)  INSERT INTO "reviews" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"  [["created_at", Sun, 30 Mar 2014 08:50:13 UTC +00:00], ["updated_at", Sun, 30 Mar 2014 08:50:13 UTC +00:00]]
   (8.4ms)  COMMIT
Redirected to localhost:3000/reviews/3

1 个答案:

答案 0 :(得分:1)

我的问题来自this gem" protected_attributes"我用于用户身份验证。我想有一种新方法,找到here