CD-RUM CD-RUM - 1 month ago 10
Ruby Question

Rails 5: can't access update method in view

I'm trying to update an attribute with a single button like so:

<%= link_to loan_product, lead_path(@lead, lead: { loan_product: loan_product }, method: :patch) %>


The params come through just fine, but
lead_path
only accesses the
show
method of the controller and not the
update
one despite the
method
being set to either
:patch
or
:put
, and because of that the attribute isn't updated.

How can I point this
link_to
to the default
update
method in the controller? I'm just rocking default resources in
routes.rb
, i.e.,
resources :leads
.

Answer

As said in my comment:

the option method: :patch is given as arg to the lead_path method, it should be passed to the link_to instead:

<%= link_to loan_product, lead_path(...), method: :patch %>