ruby on rails - No route matches [POST] "/login" -
ruby on rails - No route matches [POST] "/login" -
when submit form
<h1>log in</h1> <%= simple_form_for sessions_path |f| %> <%= f.input :email %> <%= f.input :password %> <%= f.input :remember_me, as: :boolean %> <%= f.submit 'log in' %> <% end %>
it gives me error: no route matches [post] "/login"
. true don't have route matches that, understand, should post
ing sessions#create
, have route , action. why not doing this?
routes.rb
dinnerdash::application.routes.draw 'login', to: 'sessions#new', as: 'login' 'logout', to: 'sessions#destroy', as: 'logout' 'signup', to: 'users#new', as: 'signup' root 'items#index' resources :users resources :password_resets resources :sessions resources :items "password/resets" "password/create" "password/edit" "password/update" end
sessions_controller.rb
class sessionscontroller < applicationcontroller def new end def create user = login(params[:email], params[:password], params[:remember_me]) if user redirect_back_or_to root_url, notice: 'logged in!' else flash.now.alert = 'unable login.' render :new end end def destroy logout redirect_to root_url, notice: 'logged out.' end end
rake routes
it's sorta hard read, of import points there's get /login
, not post /login
, , there's get
, post
/sessions_path
.
login_path /login(.:format) sessions#new logout_path /logout(.:format) sessions#destroy signup_path /signup(.:format) users#new root_path / items#index users_path /users(.:format) users#index post /users(.:format) users#create new_user_path /users/new(.:format) users#new edit_user_path /users/:id/edit(.:format) users#edit user_path /users/:id(.:format) users#show patch /users/:id(.:format) users#update set /users/:id(.:format) users#update delete /users/:id(.:format) users#destroy password_resets_path /password_resets(.:format) password_resets#index post /password_resets(.:format) password_resets#create new_password_reset_path /password_resets/new(.:format) password_resets#new edit_password_reset_path /password_resets/:id/edit(.:format) password_resets#edit password_reset_path /password_resets/:id(.:format) password_resets#show patch /password_resets/:id(.:format) password_resets#update set /password_resets/:id(.:format) password_resets#update delete /password_resets/:id(.:format) password_resets#destroy sessions_path /sessions(.:format) sessions#index post /sessions(.:format) sessions#create new_session_path /sessions/new(.:format) sessions#new edit_session_path /sessions/:id/edit(.:format) sessions#edit session_path /sessions/:id(.:format) sessions#show patch /sessions/:id(.:format) sessions#update set /sessions/:id(.:format) sessions#update delete /sessions/:id(.:format) sessions#destroy items_path /items(.:format) items#index post /items(.:format) items#create new_item_path /items/new(.:format) items#new edit_item_path /items/:id/edit(.:format) items#edit item_path /items/:id(.:format) items#show patch /items/:id(.:format) items#update set /items/:id(.:format) items#update delete /items/:id(.:format) items#destroy password_resets_path /password/resets(.:format) password#resets password_create_path /password/create(.:format) password#create password_edit_path /password/edit(.:format) password#edit password_update_path /password/update(.:format) password#update
try this
<%= simple_form_for :session, :url => sessions_path |f| %> # rest of form <% end %>
ruby-on-rails routes simple-form
Comments
Post a Comment