Reputation: 53
I'm trying to dynamically change what associations and methods are returned from the as_json function of my model in a rails controller action based on parameters passed to the action.
Here are the parameters being passed to the action:
{"include"=>{"service_requests"=>"status"},
"methods"=>["service_request_count"],
"program_id"=>""}
Here is what my controller action is doing:
respond_to do |format|
format.html # index.html.erb
format.json { render json: @projects.as_json(:include => params[:include]), :methods => params[:methods] }
end
This is giving the error: "can't convert Symbol into Integer". Any ideas what's causing this?
Upvotes: 1
Views: 547
Reputation: 8892
Whereas the argument you're giving to as_json is
:include => { :service_requests => :status }
it needs to be
:include => { :service_requests => { :include => :status } }
Upvotes: 2