Search code examples
ruby-on-railsactionform-for

rails 4 form_for custom action


I am using <%= form_for @invoice, url: {action: :pay} do |f| %> but the form is sent to the update action instead of the "pay" action I defined in the controller. What am I missing?


Solution

  • You have param :id in your route, and you should assign a param to id in your form action, try this

    <%= form_for @invoice, url: {action: "pay", params: {id: @invoice.id}} %>
    

    Or you can use a path

    <%= form_for @invoice, url: for_pay_path(@invoice) %>
    

    for_pay_path change to path of pay action, you can see on ouput of rake routes