Rails 4 : Table Boolean Column Update Using "link_to "with a specific value "TRUE" always -
in customer controller update method code bellow:
def update @customer= customer.find(params[:id]) if @customer.update_attributes(customer_params) redirect_to customers_path else render 'edit' end end
in view in customers index page planning add "link_to" link, if clicked, particular customers field "doc_delete" should updated value "true".
<td><%= link_to "[update", *************what here ?******** method: :put %></td>
you can pass hidden params through button_to
:
<%= button_to "update", user, method: :put, params: { doc_delete: true } %>
this create micro-form, marwen
alluded to. whilst quite inefficient, best way send data update
action.
--
another, more efficient, way define custom route/action:
#config/routes.rb resources :customers patch :doc_delete, on: :member #-> url.com/users/:id/doc_delete end #app/controllers/customers_controller.rb class customerscontroller < applicationcontroller def doc_delete @customer = customer.find params[:id] redirect_to customers_path if @customer.update doc_delete: true end end #app/views/customers/index.html.erb <% @customers.each |customer| %> <%= link_to "update", customer_doc_delete_path(customer) %> <% end %>
Comments
Post a Comment