ruby - Serialize delegate in rails -


i have 3 models in rails: user, userprofile , post

something this:

class post < activerecord::base   attr_accessible :content, :post_type   belongs_to :user    delegate :fullname, :to => :user, :prefix => "author" end  class user < activerecord::base   has_many :posts   has_one :user_info   delegate :fullname, :to => :user_info end  class userinfo < activerecord::base   attr_accessible :avatar, :fullname, :birthday, :nickname, :gender, :about    belongs_to :user end 

now use knockout manage posts @ client-side have make object json using posts.to_json. these json objects don't have attributes fullname. tried user.to_json, , these objects don't have attribute either. how can make delegate serialize json?

since fullname virtual attribute in sense:

rails 2:

posts.to_json(:method => %w(fullname)) user.to_json(:method => %w(fullname)) 

rails 3:

posts.to_json(:methods => %w(fullname)) user.to_json(:methods => %w(fullname)) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -