未定义的方法“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
有什么问题.
I don't understand what is wrong with :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屋!
查看全文