未定义的方法'stringify_keys!'红宝石在铁轨上 [英] undefined method `stringify_keys!' ruby on rails
本文介绍了未定义的方法'stringify_keys!'红宝石在铁轨上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此代码:
def addcar
@car = Car.new(params[:car])
render :action => 'list'
end
<% @allcars.each do |cell| %>
<p>
<%= link_to cell.to_s, :controller => 'car', :action => 'addcar', :car => cell.to_s %>
</p>
<% end %>
这给了我这个错误:
未定义的方法'stringify_keys!'对于本田":字符串
undefined method `stringify_keys!' for "Honda":String
我不明白:car
怎么了.
推荐答案
在addcar
方法中,您尝试创建一个新对象(create
方法),同时仅将一个字符串(params[:car]
显然设置为"Honda")传递给它.
in the addcar
method, you try to create a new object (create
method) while transfering just a string to it (params[:car]
which apparently is set to "Honda").
create
希望获得一个属性哈希值并对其进行字符串化处理
列名称.
create
expects to get an attributes hash and to stringify it's keys for
the column names.
如果您的汽车表中有一个名为name的列,请尝试以下操作:
If you have a column named name in your cars table then try this:
@car = Car.new(:name => params[:car])
这篇关于未定义的方法'stringify_keys!'红宝石在铁轨上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文