Reputation: 305
I'm using Ruby 2.0.0 and Rails 4.0.2. When I click the submit button on the edit profile page, I get this routing error:
Routing Error
No route matches [PATCH] "/users/sign_in"
I do not exactly understand how the devise routing works since the only relevant line in the routes.rb file I see is devise_for :users. Here are some of my files. Thank you.
/config/routes.rb
SampleApplication::Application.routes.draw do
resources :pins
devise_for :users
root 'pages#home'
get 'about' => 'pages#about'
get 'contact' => 'pages#contact'
end
/models/user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, #:recoverable,
:rememberable, :trackable, :validatable
has_many :pins
end
/views/devise/registrations/edit.html.erb
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>
<%= f.input :password, label: "New Password", autocomplete: "off" %>
<%= f.input :password_confirmation, label: "New Password", autocomplete: "off" %>
<%= f.input :current_password %>
<div class="form-actions">
<%= f.submit "Update", class: "btn btn-primary"%>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
<%= link_to "Back", :back %>
rake routes command
Prefix Verb URI Pattern Controller#Action
pins GET /pins(.:format) pins#index
POST /pins(.:format) pins#create
new_pin GET /pins/new(.:format) pins#new
edit_pin GET /pins/:id/edit(.:format) pins#edit
pin GET /pins/:id(.:format) pins#show
PATCH /pins/:id(.:format) pins#update
PUT /pins/:id(.:format) pins#update
DELETE /pins/:id(.:format) pins#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root GET / pages#home
about GET /about(.:format) pages#about
contact GET /contact(.:format) pages#contact
Upvotes: 2
Views: 1017
Reputation: 433
Your simple_form is pointing to the wrong submit url.
It says
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {class: 'form-horizontal'}) do |f| %
but the url
should point to the user_registration_path
, not session_path
, so
<%= simple_form_for(resource, :as => resource_name, :url => user_registration_path(resource_name), html: {class: 'form-horizontal'}) do |f| %
Upvotes: 1