Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: Invalid route name, already in use (ArgumentError)

Well the error is telling the truth, I have used the route name 'contact' twice, but one match is for a get request and the other for a post. I have been following the following tutorial for setting up Contact Form in Rails: http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/, and the author suggests adding the following to my routes file:

match 'contact' => 'contact#new', :as => 'contact', :via => :get
match 'contact' => 'contact#create', :as => 'contact', :via => :post

However that gives me the following error:

Invalid route name, already in use: 'contact'  (ArgumentError)

Here is my own routes.rb file:

Fls::Application.routes.draw do
  root 'welcome#index'
  match 'contact' => 'contact#new', :via => :get
  match 'contact' => 'contact#create', :as => 'contact', :via => :post
end
like image 639
Thalatta Avatar asked Dec 20 '25 23:12

Thalatta


1 Answers

Do the following instead of above:

resource :contact, only: [:new, :create]

OR

get 'contact' => 'contact#new'
post 'contact' => 'contact#create', :as => 'contact'
like image 57
Zakwan Avatar answered Dec 22 '25 15:12

Zakwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!