Rails HashWithIndifferentAccess - 错误

时间:2013-02-27 17:27:44

标签: ruby-on-rails ruby ruby-on-rails-3

我正在保存这样的哈希会话:

 session[:review] = {:content => params[:review], :rating => params[:rating], :school_id => params[:school_id]} 

当我将它保存到数据库时:

Review.create!(:content => session[:review][:content], :school_id => session[:review][:school_id], :user_id => current_user, :rating => session[:review][:rating])

它将值保存到一列中,如下所示:

--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
rating: '1'
content: somehting skjnfjkbf

为什么以及如何解决此问题?

1 个答案:

答案 0 :(得分:0)

嗯。我不确定错误是如何产生的。

但是,下面的代码可以解决你的问题。

Review.create!(session[:review].merge(user_id: current_user))