[英]Ruby on Rails Devise Edit Registration Routing Error
I'm using Ruby 2.0.0 and Rails 4.0.2. 我正在使用Ruby 2.0.0和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" 没有路由匹配[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. 我不完全了解devise路由的工作方式,因为我看到的route.rb文件中唯一相关的行是devise_for:users。 Here are some of my files.
这是我的一些文件。 Thank you.
谢谢。
/config/routes.rb /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 /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 /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
Your simple_form is pointing to the wrong submit url. 您的simple_form指向错误的提交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 但
url
应指向user_registration_path
,而不是session_path
,因此
<%= simple_form_for(resource, :as => resource_name, :url => user_registration_path(resource_name), html: {class: 'form-horizontal'}) do |f| %
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.