我一直在使用acts_as_commentable_with_threading gem,我无法获得保存的评论。
我的控制器:
class CommentsController < ApplicationController
def create
@comment_hash = params[:comment]
@obj = @comment_hash[:commentable_type].constantize.find(@comment_hash[:commentable_id])
# Not implemented: check to see whether the user has permission to create a comment on this object
@comment = Comment.build_from(@obj, current_user, @comment_hash[:body])
if @comment.save
flash[:notice] = "New comment saved!!!!!"
redirect_to status_path(@obj)
#redirect_to profiles_path(current_user)
else
flash[:alert] = "didn't save"
redirect_to status_path(@obj)
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def comment_params
params.require(:comment,:commentable_id,:commentable_type, :user_id, :body)
end
end
当我检查开发日志时,我可以看到散列中的值都已填充,我可以看到事务开始保存,但会立即回滚。
Started POST "/comments" for 127.0.0.1 at 2014-01-30 10:47:54 +0100
Processing by CommentsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ojRIz0hj0m8BL613Q9W4DHkYNZqO8eeMvR2gEM6Qhp8=", "comment"=> {"body"=>"test comment", "commentable_id"=>"52", "commentable_type"=>"Status"}, "commit"=>"Submit"}
[1m[35mStatus Load (0.1ms)[0m SELECT "statuses".* FROM "statuses" WHERE "statuses"."id" = ? ORDER BY created_at DESC LIMIT 1 [["id", "52"]]
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 6 ORDER BY "users"."id" ASC LIMIT 1[0m
[1m[35m (0.1ms)[0m begin transaction
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
Redirected to http://localhost:3000/statuses/52
Completed 302 Found in 5ms (ActiveRecord: 0.6ms)