ruby on rails - Accessing a model from another model -
after post.all
, i'm trying return json array of post objects custom attribute. here have:
@posts = post.includes(:profil).page(params[:page]).order('created_at desc') render json: @posts.to_json(:include => :profil, :methods => [:image_url, :vote_modificator])
this method correctly returns list of posts, including profil
, custom attribute image_url
. have model vote
, belongs profil
, post
:
class vote < activerecord::base attr_accessible :value belongs_to :profil belongs_to :post end
i want insert in each post vote
value corresponding , current_user
defined in application_controller.rb
:
def current_user @current_user ||= user.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token] end helper_method :current_user
i tried add method in to_json
, method defined in model can't access helper. solution solve problem?
Comments
Post a Comment