我不确定它是如何发生的,但看起来你的 params 对象只是一个散列......而不是一个ActionController::Parameters
目的。当 params 只是一个哈希值时:
params = {"utf8"=>"✓", "authenticity_token"=>"0FqFTx2EjCIO+R+rm97lF15+id4b452n+dBuUNxAL9U=", "link"=>{"url_address"=>"http://www.google.com", "alt_text"=>"", "version_number"=>"", "group_id"=>"49", "content_date"=>"08/18/2014"}, "commit"=>"Save"}
params.require(:link)
=> TypeError: no implicit conversion of Symbol into String
params.class
=> Hash
但如果它是一个 ActionController::Parameters 对象
params2 = ActionController::Parameters.new({"utf8"=>"✓", "authenticity_token"=>"0FqFTx2EjCIO+R+rm97lF15+id4b452n+dBuUNxAL9U=", "link"=>{"url_address"=>"http://www.google.com", "alt_text"=>"", "version_number"=>"", "group_id"=>"49", "content_date"=>"08/18/2014"}, "commit"=>"Save"})
params2.require(:link)
=>{"url_address"=>"http://www.google.com", "alt_text"=>"", "version_number"=>"", "group_id"=>"49", "content_date"=>"08/18/2014"}
params2.class
=>ActionController::Parameters
你正在做某事吗params
before link_params
抓住它了吗?
编辑:
根据API Docs http://apidock.com/rails/ActionController/Parameters, 强参数仅在 Rails 4.0.2 中可用。如果您使用的是早期版本,则必须坚持使用 Rails 3 attr_accessible