0
我创造了这个形式,使用simple form gem,对后级的论坛:Rails的表“必须存在”协会
<%= simple_form_for @post do |p| %>
<%= p.input :title, label: false, placeholder: 'Title', required: true %>
<%= p.input :description, as: :text, label: false, placeholder: 'Describe your post', required: true %>
<%= p.association :category, label: false, required: true,
collection: Category.order(:title), prompt: 'Choose category' %>
<%= p.button :submit %>
<% end %>
现在我去的网页,并尝试创建一个职位,我得到这个:
我不知道如何着手,因为这个对象(C,C++等)的存在。下面是他们创造在哪里,在seeds.rb
c1 = Category.create(title: "C++", image_url: 'http://www.freeiconspng.com/uploads/c--logo-icon-0.png')
c2 = Category.create(title: "Rails", image_url: 'http://perfectial.com/wp-content/uploads/2015/02/ruby.png')
c3 = Category.create(title: "Python", image_url: 'http://python.net/~goodger/projects/graphics/python/newlogo-repro.png')
c4 = Category.create(title: "Cobol", image_url: 'http://insights.dice.com/wp-content/uploads/2013/06/cobol.png')
c5 = Category.create(title: "C", image_url: 'https://d13yacurqjgara.cloudfront.net/users/28449/screenshots/1040285/cap-logo-ideas3.png')
c6 = Category.create(title: "Perl", image_url: 'http://news.perlfoundation.org/onion_logo.png')
是的,我也跑耙分贝:种子,并试图之前重新启动服务器。
您的意思是'高清post_attributes'? –
是的,做一点点多任务:) – max
另外,你应该在你的'seeds.rb'中使用'.create!' - 如果验证不通过而不是静默地失败,它会引发一个错误。 – max