mardi 3 novembre 2015

Rails not hitting the right route Routing error

having an issue where my form action is not hitting the right route. I know I must be doing something wrong with the path but rails makes this pretty easy so I don't know why it keeps trying to hit the post method on '/' instead of the user_path which is /users

here is my form

<form  action="<% users_path %>" method="post">
<input type="email" name="user[email]" placeholder="your email"/>
# other inputs and submit

here is the users_controller

def create
   @user = User.new(user_params)
   if @user.save
      flash[:message] = @user.email +" Created succesfully!"
   else
      flash[:message] @user.errors.full_messages.to_sentence
   redirect_to root_path
end

and here is routes.rb

root 'application#welcome'
post 'users' => 'users#create'

rake routes output

Prefix Verb URI Pattern      Controller#Action   
root   GET  /                application#welcome  
users  POST /users(.:format) users#create

and finally the error

Routing Error No route matches [POST] "/"

here is my directory structure

├── app
│   ├── assets
│   │   ├── images
│   │   ├── javascripts
│   │   │   ├── application.js
│   │   │   └── users.coffee
│   │   └── stylesheets
│   │       ├── application.css
│   │       └── users.scss
│   ├── controllers
│   │   ├── application_controller.rb
│   │   ├── concerns
│   │   └── users_controller.rb
│   ├── helpers
│   │   ├── application_helper.rb
│   │   └── users_helper.rb
│   ├── mailers
│   ├── models
│   │   ├── concerns
│   │   └── user.rb
│   └── views
│       ├── application
│       │   └── welcome.html.erb
│       ├── layouts
│       │   └── application.html.erb
│       └── users

Aucun commentaire:

Enregistrer un commentaire