我正在完成简单的应用程序。我正在使用Devise gem作为登录和注册提供商。
我的问题:当用户单击他的电子邮件确认链接时,出现路由错误:
No route matches {:action=>"update_account", :controller=>"devise/users", :locale=>:ru}
我的确认链接如下所示:
www.mysite.com/users/confirmation?confirmation_token=dRRtTzVTy8gSF_D8FehF
在应用程序布局中,我有用户更新表单,用户可以在其中编辑他的详细信息。
<%= form_for(@user, :url => { :action => "update_account",:controller =>"users" }, html: { "data-parsley-validate" => true, :id=>"user-edit-profile"},remote: true) do |f| %>
...
<%end%>
我的路线:
scope "(:locale)", :locale => /lv|ee|ru/ do
devise_for :users, :controllers => {:registrations=> "registrations"}
resource :user do
collection do
post 'update_account'
end
end
end
UsersCotroller:
class UsersController < ApplicationController
before_action :set_user, only: [:show, :upvote, :downvote]
before_action :authenticate_user!
respond_to :html, :js
def index
@users = User.all
end
def show
respond_with(@user)
end
def update_account
@user = User.find(current_user.id)
@user.attributes = user_params
respond_to do |format|
if @user.save(validate: false)
# sign_in :user, @user, bypass: true
format.html
format.json
else
format.html { render action: 'edit' }
format.json { render json: @user.errors.full_messages, status: :unprocessable_entity }
end
end
end
def new
@user = User.new
respond_with(@user)
end
def edit
@user = current_user
end
def create
@user = User.new(user_params)
flash[:notice] = 'User was successfully created.' if @user.save
respond_with(@user)
end
def update
flash[:notice] = 'User was successfully updated.' if @user.update(user_params)
respond_with(@user)
end
def destroy
@user.destroy
respond_with(@user)
end
def upvote
@user.liked_by current_user
flash[:notice] = 'Upvote added.' if @user.vote_registered?
redirect_to @user
end
def downvote
@user.downvote_from current_user
flash[:notice] = 'Downvote added.' if @user.vote_registered?
redirect_to @user
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
# NOTE: Using `strong_parameters` gem
params.required(:user).permit(:password, :password_confirmation, :current_password,:name,:role, :email,:bypass_humanizer, :not_a_robot)
end
end
路线:
new_user_session GET (/:locale)/users/sign_in(.:format) devise/sessions#new {:locale=>/lv|ee|ru/}
user_session POST (/:locale)/users/sign_in(.:format) devise/sessions#create {:locale=>/lv|ee|ru/}
destroy_user_session DELETE (/:locale)/users/sign_out(.:format) devise/sessions#destroy {:locale=>/lv|ee|ru/}
user_password POST (/:locale)/users/password(.:format) devise/passwords#create {:locale=>/lv|ee|ru/}
new_user_password GET (/:locale)/users/password/new(.:format) devise/passwords#new {:locale=>/lv|ee|ru/}
edit_user_password GET (/:locale)/users/password/edit(.:format) devise/passwords#edit {:locale=>/lv|ee|ru/}
PATCH (/:locale)/users/password(.:format) devise/passwords#update {:locale=>/lv|ee|ru/}
PUT (/:locale)/users/password(.:format) devise/passwords#update {:locale=>/lv|ee|ru/}
cancel_user_registration GET (/:locale)/users/cancel(.:format) registrations#cancel {:locale=>/lv|ee|ru/}
user_registration POST (/:locale)/users(.:format) registrations#create {:locale=>/lv|ee|ru/}
new_user_registration GET (/:locale)/users/sign_up(.:format) registrations#new {:locale=>/lv|ee|ru/}
edit_user_registration GET (/:locale)/users/edit(.:format) registrations#edit {:locale=>/lv|ee|ru/}
PATCH (/:locale)/users(.:format) registrations#update {:locale=>/lv|ee|ru/}
PUT (/:locale)/users(.:format) registrations#update {:locale=>/lv|ee|ru/}
DELETE (/:locale)/users(.:format) registrations#destroy {:locale=>/lv|ee|ru/}
user_confirmation POST (/:locale)/users/confirmation(.:format) devise/confirmations#create {:locale=>/lv|ee|ru/}
new_user_confirmation GET (/:locale)/users/confirmation/new(.:format) devise/confirmations#new {:locale=>/lv|ee|ru/}
GET (/:locale)/users/confirmation(.:format) devise/confirmations#show {:locale=>/lv|ee|ru/}
update_account_user POST (/:locale)/user/update_account(.:format) users#update_account {:locale=>/lv|ee|ru/}
user POST (/:locale)/user(.:format) users#create {:locale=>/lv|ee|ru/}
new_user GET (/:locale)/user/new(.:format) users#new {:locale=>/lv|ee|ru/}
edit_user GET (/:locale)/user/edit(.:format) users#edit {:locale=>/lv|ee|ru/}
GET (/:locale)/user(.:format) users#show {:locale=>/lv|ee|ru/}
PATCH (/:locale)/user(.:format) users#update {:locale=>/lv|ee|ru/}
PUT (/:locale)/user(.:format) users#update {:locale=>/lv|ee|ru/}
DELETE (/:locale)/user(.:format) users#destroy {:locale=>/lv|ee|ru/}
help GET (/:locale)/help(.:format) help#index {:locale=>/lv|ee|ru/}
rules GET (/:locale)/rules(.:format) rules#index {:locale=>/lv|ee|ru/}
我试图重新启动服务器,但没有成功。
我找不到任何类似的问题,所以我正在创建一个新的问题。
提前致谢。
最佳答案
使用如下所示的简单解决方案:
<%= form_for(@user, :url => "/user/update_account", html: { "data-parsley-validate" => true, :id=>"user-edit-profile"},remote: true) do |f| %>
.....
<%end%>
关于ruby-on-rails - 设计确认链接给我路由错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33022307/