我对Rails(v4.0.0)和Devise(v3.5.2)上的Ruby(v2.0.0)有点陌生,并且由于某种原因,一旦注册后就无法退出。但是,如果我手动进入MySQL2数据库并完全删除用户,则“注册/登录”页面将再次变为可用。
我没有触摸过session_store.rb初始化程序或其他任何东西。我身处困境,需要先解决此问题,然后才能继续前进。
非常感谢您的帮助。
我的“注册”表单的逻辑非常简单:
<% if user_signed_in? %>
<%= current_user.email %> / <%= link_to "Sign Out", destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to "Sign Up", new_user_registration_path %> / <%= link_to "Log In", new_user_session_path %>
<% end %>
我的devise.rb文件还配置为使用:delete:
config.sign_out_via = :delete
我的Gemfile中有JQuery:
# jQuery
gem 'jquery-rails'
gem 'jquery-ui-rails'
我在application.js中初始化了它们:
//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require jquery.details
//= require jquery.textchange
我的route.rb已正确配置(注释掉的“ #devise_for:users”表明我已经尝试了两种方法,但均无效果):
Selfstarter::Application.routes.draw do
root :to => 'home#index'
#devise_for :users
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end
...
end
我的耙路反映出:
Prefix Verb URI Pattern Controller#Action
root GET / home#index
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
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
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
user.rb型号:
class User < ActiveRecord::Base
has_many :orders
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
万一需要它,请使用database.rb:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: dbname
pool: 5
username: dbusername
password: dbpass
#socket: /opt/local/var/run/mysql5/mysqld.sock
我不知道下一步该怎么做,并搜寻了Google和Stack Overflow。我什么都没找到。
我还要提及的是,我真的很想遵守RESTful约定,并且尽可能不要使用:get方法。
编辑:我的日志文件
Started DELETE "/users/sign_out" for 127.0.0.1 at 2015-08-21 11:28:17 -0400
Started DELETE "/users/sign_out" for 127.0.0.1 at 2015-08-21 11:28:17 -0400
Processing by Devise::SessionsController#destroy as HTML
Processing by Devise::SessionsController#destroy as HTML
User Load (3.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
User Load (3.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Can't verify CSRF token authenticity
Can't verify CSRF token authenticity
(1.0ms) BEGIN
(1.0ms) BEGIN
(1.0ms) COMMIT
(1.0ms) COMMIT
Redirected to http://localhost:3000/
Redirected to http://localhost:3000/
Completed 302 Found in 66ms (ActiveRecord: 5.0ms)
Completed 302 Found in 66ms (ActiveRecord: 5.0ms)
我终于找到了解决方案。我只需要在<%= csrf_meta_tags %>
我的application.html.erb标头标签中添加它,就可以像一个魅力一样工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句