Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No route matches [POST] "/sessions/user"

I just installed Devise on my app, I had previously done it by scratch like Michael Hartl tutorial.

Currently I can sign up and log out. But when I do log in it gives an error:

No route matches [POST] "/sessions/user"

it happens when I click on the sign in/log in button with or without the (correct) password.

My route file is:

SampleApp::Application.routes.draw do
devise_for :users, path_names: { sign_in: "login", sign_out: "logout"}

resources :users do
  resources :bookings, only: [:show]
  end
resources :bookings
resources :sessions

# match '/signup',  to: 'devise/registrations#new', via: :get
# match '/signin',  to: 'devise/sessions#new', via: [:post, :get]
# match '/signout', to: 'devise/sessions#destroy', via: :delete
match '/admin',   to: 'admin#new', via:  :get
match "bookings/new", to: 'bookings#new', via: [:post, :get]

devise_scope :user do 
  root to: 'static_pages#home'
end

[EDIT]

My form is the default from devise:

<h2>Sign in</h2>

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>
  <div><%= f.label :password %><br />
  <%= f.password_field :password %></div>
  <% if devise_mapping.rememberable? -%>
    <div><%= f.check_box :remember_me %>
    <%= f.label :remember_me %></div>
  <% end -%>
  <div><%= f.submit "Sign in" %></div>
<% end %>

Currently I don't have any code on Session Controller nor Helper like in the Michael Hartl tutorial

My rake routes regarding Sessions are as follows:

            sessions GET      /sessions(.:format)                    sessions#index
                     POST     /sessions(.:format)                    sessions#create
         new_session GET      /sessions/new(.:format)                sessions#new
        edit_session GET      /sessions/:id/edit(.:format)           sessions#edit
             session GET      /sessions/:id(.:format)                sessions#show
                     PATCH    /sessions/:id(.:format)                sessions#update
                     PUT      /sessions/:id(.:format)                sessions#update
                     DELETE   /sessions/:id(.:format)                sessions#destroy

[SOLVED]

I updated the routes file

  devise_scope :user do 
    root to: 'static_pages#home'
    match '/sessions/user', to: 'devise/sessions#create', via: :post
  end
like image 745
tvieira Avatar asked Aug 22 '13 22:08

tvieira


2 Answers

Add the following lines in the routes file

post ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'

Also remove match ':controller(/:action(/:id(.:format)))' ->causes a conflict in later versions

like image 100
Shine Cardozo Avatar answered Nov 20 '22 13:11

Shine Cardozo


A possible solution I came up is:

 devise_scope :user do 
    root to: 'static_pages#home'
    match '/sessions/user', to: 'devise/sessions#create', via: :post
  end
like image 39
tvieira Avatar answered Nov 20 '22 13:11

tvieira