I would like to be able to pass “params” to the “is_following” method as follows:
respond_to |format|
format.json { render json: @user, :methods => [:is_following params] }
end
However, when I put “params” after the method name, it throws an error:
syntax error, unexpected tIDENTIFIER, expecting ']'
.
.
When I render the JSON (without the is_following method), it looks like this:
[{"id":81,"image_url":"https://graph.facebook.com/123213123/picture?type=large","full_name":"John Johnson"},{"id":85,"image_url":"https://graph.facebook.com/123123123/picture?type=large","full_name":"Bill Nye"}]
I want to add the is_following method so that the JSON loos like this:
[{"id":81,"image_url":"https://graph.facebook.com/123213123/picture?type=large","full_name":"John Johnson",'is_following'=>4},{"id":85,"image_url":"https://graph.facebook.com/123123123/picture?type=large","full_name":"Bill Nye",'is_following'=>9}]
EDIT
def friends
@user = User.first
respond_to do |format|
format.json { render json: @user.friends.order("first_name ASC"), :methods => [:is_following], :only => [:id] }
end
end
and is_following method in model is:
def is_following params
return Friendship.where("user_id = ? AND friend_id = ?", params[:user_id], self.id).count
end
Anyone know how to solve this? I will give you a million dollars.
Brian,
Just change this code:
to
EDIT
Here is a better way to do this anyway: