json - Rails 3.2.2 - Possible to add custom node to as_json -
as it's not possible me use json templating engine (jbuilder or rabl) per rails3 actionview template handlers doesn't work on production server i'm wondering how best change controller action include custom node as_json (or else)
class mobile::androiduserscontroller < securemobileusercontroller skip_before_filter :authorize, :only => :create respond_to :json # post /mobile_users # post /mobile_users.xml def create @mobile_user = androiduser.find_by_auth(params[:mobile_user][:auth]) unless @mobile_user @mobile_user = androiduser.new(params[:mobile_user]) else @mobile_user.attributes = params[:mobile_user] end respond_to |format| if @mobile_user.save format.json #add custom token node here else :unprocessable_entity } format.json { render json: @mobile_user.errors, status: :unprocessable_entity } :unprocessable_entity } end end end end
i need add custom node called token has value calling method on mobileuser class
:token => mobileuser.next_token
you can change call as_json this:
format.json {render :json => @mobile_user.as_json(:methods => [:next_token])}
Comments
Post a Comment