collection_select方法在Rails 3.1.1中给出错误 [英] collection_select method gives error in Rails 3.1.1

查看:95
本文介绍了collection_select方法在Rails 3.1.1中给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Category的模型和其他模型产品.他们具有has_many和belongs_to关系. 但是我认为代码

I have a Model called Category and other Model Product. They have has_many and belongs_to relation. But code in my view

    <p><%= f.collection_select(:product, :category_id, Category.all, :id, :name)%>

在给我

 undefined method `merge' for :name:Symbol

有什么线索吗?

推荐答案

您可能有类似这样的事情:

Chances are you have something like this:

<%= form_for @product do |f| %>

由于f已经与product绑定,因此您不需要将其作为第一个参数,因此应该为:

Because f is already tied to product, you don't need to include it as your first argument, so it should just be:

<%= f.collection_select :category_id, Category.all, :id, :name %>

或者,您不能使用f.:

<%= collection_select :product, :category_id, Category.all, :id, :name %>

这篇关于collection_select方法在Rails 3.1.1中给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆