I am building a basic grocery list application in Rails. Each "item" has two properties: name and checked. Name is just the name of the item. Checked is supposed to indicate whether the user has "checked off" the item on their grocery list.
I put a simple method in my item controller to address this. The problem is the method will only change false to true. It will not reverse and allow me to uncheck items.
Here is the method, which is inside my item controller:
def checked
@item = Item.find(params[:id])
if [email protected]
@item.update(checked: :true)
else
@item.update(checked: :false)
end
redirect_to root_path
end
This will only work for the false to true conversation. The second half of the if statement does not appear to be working. Thoughts?
@item.update(checked: [email protected]?)-- Your code does not work because it is actually sending asymbolobject instead oftrueorfalse, remove that semi-colon in front oftrueandfalseand it should work.