I have two models:
我有两个型号:
Project.rb
Project.rb
class Project < ActiveRecord::Base
belongs_to :customer
end
and Customer.rb
和Customer.rb
class Customer < ActiveRecord::Base
has_many :projects
end
Inside the _form.html.erb I have:
在_form.html.erb里面我有:
<p>
<label>Select Customer</label>
<%= f.collection_select :customer_id, Customer.all, :id, :name, :include_blank => true %>
</p>
Which should Collect the Customers from the Customer model and display all the customers, finally it should assign the value to the customer_id which is in projects table.
哪个应该从客户模型收集客户并显示所有客户,最后应该将值分配给项目表中的customer_id。
Rite now the everything is passing when i check the log. When I select the first customer with value=1, it passes customer_id = "1" in my log but it doesn't get stored in the table. It shows customer_id = nil in the projects table.
现在,当我检查日志时,一切都过去了。当我选择值为1的第一个客户时,它会在我的日志中传递customer_id =“1”,但它不会存储在表中。它在项目表中显示customer_id = nil。
Can someone help. Thanks :)
有人可以帮忙吗谢谢 :)
1 个解决方案
#1
3
Do check that you added customer_id in attr_accessible method like,
请检查您是否在attr_accessible方法中添加了customer_id,例如,
class Project
attr_accessible :your_other_attributes, :customer_id
end
#1
3
Do check that you added customer_id in attr_accessible method like,
请检查您是否在attr_accessible方法中添加了customer_id,例如,
class Project
attr_accessible :your_other_attributes, :customer_id
end