所以我使用rails 4并使用以下方法将我的用户成功链接到我的Products表:
users.rb的
has_and_belongs_to_many :products
accepts_nested_attributes_for :products
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :role_ids, :product_ids
products.rb
has_and_belongs_to_many :users
查看/ userse / _form.html.erb
<%= simple_form_for(@user) do |f| %>
<%= f.association :products, label: "Product Release Email", value_method: :id, :as => :check_boxes %>
但是我想更改变量名:产品到:productReleaseEmail我试过changint users.rb到
has_and_belongs_to_many :productReleaseEmail, :class_name => "product"
但我收到错误“未初始化的常量User :: product”。所以我假设我的一些参考文献错了。
答案 0 :(得分:2)
将其资本化:
class_name: "Product"