게시물 모델과 카테고리 모델이 있습니다. 활성 레코드가있는 simple_form gem을 설치했습니다. 나는 기초와 간단한 형태 협회의 this github 단계를 구현하려고합니다. 하지만 해결할 수없는 이상한 오류가 나타납니다.# <Post : 0xade8ce4>에 대한 정의되지 않은 메소드 'category_id'
posts.rb
class Post < ActiveRecord::Base
validates_presence_of :title, :body
has_many :comments
belongs_to :category
end
category.rb
class Category < ActiveRecord::Base
has_many :posts
end
_form.html.erb HD1 말했듯이
<%= simple_form_for @post do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.input :title %>
</div>
<div class="field">
<%= f.input :body %>
</div>
<div class="field">
<%= f.association :category %>
</div>
<div class="actions">
<%= f.button :submit %>
</div>
<% end %>
당신이 게시물 모델의 열 CATEGORY_ID이 있습니까 실행하면 마이그레이션을해야합니까? – hd1
고마워 ... 트릭을 한 ... D – Shuvro