I want to return just the elements that belong to a user. The user_id value is a column from Run. What I want is to select just the runs that are from the current_user.
def index
@runs = Run.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @runs }
end
end
As tried something like
@runs = Run.where(user_id= => current_user.id)
But it didn’t worked. How should I do it?
If you have an association between your User model and your Run model you should be able to do simply
current_user.runs. For example:I don’t know your actual DB schema or model names, though, so I can’t be sure if this is correct for your situation.