未定义的方法'stringify

编程入门 行业动态 更新时间:2024-10-28 20:21:10
本文介绍了未定义的方法'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

本文发布于:2023-10-11 04:30:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1480686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   方法   stringify

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!