Gareth Burrows
Gareth Burrows

Reputation: 1182

rails form action missing route

Ruby 1.9.3 and using HAML.

Trying to build a form to go to a specific action, but having problem with routing. The code on the form is

%form#feedback_form{:action=>"give_feedback_account_path", :method => 'post', :style => "padding: 0 5px;"}
  %input{:name => "authenticity_token", :value => form_authenticity_token, :type => "hidden"}

  blah blah blah

  .field
    %input#feedback_submit{:type => "submit", :value => "give feedback"}

When I try to submit the form I get a 404 response, and looking at the server log gives me...

Started POST "/give_feedback_account_path" for 127.0.0.1 at 2014-06-03 10:07:12 +0100
ActionController::RoutingError (No route matches "/give_feedback_account_path"):

When I run rake routes to get the details I get

give_feedback_account POST   /account/give_feedback(.:format)  
{:action=>"give_feedback", :controller=>"accounts"}

What am I missing?

Upvotes: 0

Views: 105

Answers (2)

mus
mus

Reputation: 499

change this

:action=>"give_feedback_account_path"

to this

:action => give_feedback_account_path 

give_feedback_account_path is a method. You want to call it, to get the actual path.

Upvotes: 0

Marek Lipka
Marek Lipka

Reputation: 51151

Your url is /give_feedback_account_path, which is not good. To fix it, you can use form_tag helper:

= form_tag give_feedback_account_path, method: 'post', style: 'padding: 0 5px;' do
  // your form goes here

Upvotes: 2

Related Questions