本文介绍了未定义的方法'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
发布评论