Hi I am trying to create a custom controller that return a method as json.
Here my controller
respond_to :json
def rates
@event = Event.find(params[:id])
respond_with @event.avg_rating
end
Now I have my model with the following method
# returns the average rating for that event
def avg_rating
@avg = self.ratings.average(:stars)
@avg ? @avg : 0
end
However when i get the respond I get this:
3.75
What I would like is a standard json respond either {"event": "3.75"}
But I am not sure what to use to simply transform it to make an answer like that