jean Zaniloi jean Zaniloi - 5 months ago 11
Ruby Question

RoR Active record 'where' doesn't work properly

This is my code, the first part is the problem, and the second is perfectly working.

def show
if @user.cooker?
@pushs = @user.pushs.where(taked_by = @user.id)
else
@pushs = @user.pushs
end
end


Well the code say, if I'm a cooker, I want to display all the push where the variable :taked_by is has the same id than my user.id

And the second par say that if I'm not a cooker, display all my own push.

Answer

Do taked_by: @user.id or :taked_by => @user.id

def show
  if @user.cooker?
    @pushs = @user.pushs.where(taked_by: @user.id)
  else 
    @pushs = @user.pushs
  end
end

Let me know if it worked.

Comments