I have a link that looks like this in the object’s show view:
<%= link_to "Approve", object_path(@object, status: true), method: :put, confirm: "Are you sure?", class: 'button' %>
The update action in the controller is standard and the object’s regular edit form works just fine. But for some reason, this link isn’t updating the boolean field to true…
Is there something that I did wrong with this link?
EDIT: Update Section of Controller
def update
@object = Object.find_by_certain_field(params[:id])
if @object.update_attributes(params[:object])
flash[:success] = "Object Updated"
redirect_to @object
else
render 'edit'
end
end
object_path(@object, status: true)causesparams[:status]to be true and notparams[:object][:status]as you wish, thus not updating the object with@object.update_attributes(params[:object])If you want to keep using the current code pattern just add
before
and everything should be fine.
Otherwise I’d avise you to make a form for this update call: