我正在完成简单的应用程序。我使用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/}
我尝试重启服务器但没有成功。
我无法找到任何类似的问题,所以我正在制作新问题。
提前致谢。
答案 0 :(得分:4)
使用如下所示的简单解决方案:
<%= form_for(@user, :url => "/user/update_account", html: { "data-parsley-validate" => true, :id=>"user-edit-profile"},remote: true) do |f| %>
.....
<%end%>
答案 1 :(得分:1)
您的应用程序正在update_account
下搜索:controller=>"devise/users"
行为,因为您在路由中有devise_for :users
,同时您定义了users controller
继承自ApplicationController
所有设备控制器都继承自Devise::ControllerName
,所以要解决这个问题
users
或users controller
Devise
下定义此功能
答案 2 :(得分:1)
将'资源:用户执行'更改为'资源:用户执行'
<强>路线:强>
scope "(:locale)", :locale => /lv|ee|ru/ do
devise_for :users, :controllers => {:registrations=> "registrations"}
resource :users do
collection do
post 'update_account'
end
end
end
答案 3 :(得分:-1)
您的<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<a href="http://stacksnippets.net/Scripts/xx.pdf">link1</a>
<a href="http://stacksnippets.net/Scripts/xx1.pdf">link2</a>
<br/><br/>
<button id="printHref" >Print Href</button><button id="changeHref" >Remove base from Href</button>
<br/>
Link1 Href:<p id="link1href"></p>
Link2 Href:<p id="link2href"></p>
似乎没有使用:confirmable
的{{1}}模块
请添加此devise
。您可以关注this official链接。