Well, as_json really accepts hash parameters, so I guess you could name it with
respond_with({:posts => @posts.as_json(:params => params)})
You can then refer to the parameters in the as_json definition:
def as_json(options = {}) params = options[:params] || {} { name: self.name, params_id: params[:id] ... } end
source share