2013-04-18 49 views
1

型號

def to_json 
    p 'ppp' 
    p UNDISPLAYABLE_SIGNS 
    if sign.in? UNDISPLAYABLE_SIGNS 
    {code: code} 
    else 
    super 
    end 
end 

控制器

render json: {currency: @currency, savedInUser: true} 

PPP沒有在服務器控制檯打印出來,我怎麼能定製我的JSON響應,我在做什麼錯?定製to_json不會被調用Rails中

回答

1

是as_json不to_json

def as_json 
    p 'ppp' 
    p UNDISPLAYABLE_SIGNS 
    if sign.in? UNDISPLAYABLE_SIGNS 
    {code: code} 
    else 
    super 
    end 
end