2014-01-13 7 views
0

게시물 모델과 카테고리 모델이 있습니다. 활성 레코드가있는 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 %> 
+0

당신이 게시물 모델의 열 CATEGORY_ID이 있습니까 실행하면 마이그레이션을해야합니까? – hd1

+0

고마워 ... 트릭을 한 ... D – Shuvro

답변

1

당신은 아마 게시물 모델의 category_id를 놓치고 .

rails g migration AddIdToPost

및 마이그레이션 파일에

이 :

def change 
    add_column :posts, :category_id, :integer 
end 

다음 rake db:migrate

+0

트릭을 한 사람. 나는 레일에서 새롭다. 그리고이 바보 같은 물건은 아직 따라 잡지 마라. 나를 도와 줘서 고마워. :디 – Shuvro

관련 문제