2011-09-22 8 views
0

레일 2.3.11을 사용하고 있습니다. 나는 포스트 및 고객 정보를 해당 더불어, GET 호출에 대한 XML 응답을 반환하고 싶어, 내 posts_controller에서오류 NoMethodError (정의되지 않은 메서드 'ActiveRecord :: Associations :: BelongsToAssociation : 0xb6c9b45c')

# Table name: customers 
# id     :integer(4)  not null, primary key 
# Name    ::string(255)  default("Anonymous") 
... 

class Customer < ActiveRecord::Base 
    has_many :posts 
... 

# Table name: posts 
# id     :integer(4)  not null, primary key 
# customer_id   :integer(4) 
... 

class Post < ActiveRecord::Base 
    belongs_to :customer 
... 

: 나는이 개 테이블 고객과 게시물이 있습니다.

respond_to do |format| 
    format.xml { render :xml => (@customer + @posting)} 

이것은 아주 사소한 문제로 보인다 내가 여기에 몇 가지 기본 사항을 누락 :

@customer = Customer Details 
@posting = Corresponding Post 

다음 줄은 오류 NoMethodError (undefined method '+' for ActiveRecord::Associations::BelongsToAssociation:0xb6c9b45c)가 발생합니다. 이 오류를 이해할 수있는 사람이 있습니까? 혹시 고객이 작성한 게시물을하려면

format.xml { render :xml => @posting.to_xml(:include => :customer) } 

사용합니다 : :

format.xml { render :xml => @customer.to_xml(:include => :posts) } 

을 그냥을 참고로 나는 단일 인스턴스 버전의 이름을 것입니다 ..이 필요한 것처럼

답변

0

는 소리 귀하의 개체의 .. 그래서 게시물 개체는 @ 게시물 될 것입니다 :)

관련 문제