0
我已經實施了設計正常工作的設計。當用戶註冊了他們第一次獲得:設計路由可確認
重新定向到應用程序根目錄位於localhost:3000/EN
閃存公告稱「與確認鏈接的郵件已發送到您的電子郵件地址,請打開鏈接以激活您的帳戶。「
到目前爲止好。
我再更新應用控制器:
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
end
新簽約用戶然後發現自己被重定向到本地主機:3000/EN /用戶/ sign_in,使用易混淆的消息「您需要登錄或註冊然後繼續。「
我一直在瀏覽設計how to's,但尚未破解它。解決這個問題最簡單的方法是什麼?
更新
這裏是應用程序控制器的更多詳細信息:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user!
before_filter :set_i18n_locale_from_params
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = "Access denied!"
redirect_to root_url
end
protected
def set_i18n_locale_from_params
...
end
end
更新
這裏是日誌的要求。
Started POST "/en/users" for 127.0.0.1 at 2012-10-05 17:28:37 +0100
[17:28:37] Processing by Devise::RegistrationsController#create as HTML
[17:28:37] Parameters: {"utf8"=>"✓", "authenticity_token"=>"xUGLBMvZVWrtqLWpnAsa7R361QaGrOz/aVfEwvlS6xY=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up", "locale"=>"en"}
[17:28:37] (0.1ms) BEGIN
[17:28:37] User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
[17:28:37] User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'a2XPMojypDn6uzzVAqcs' LIMIT 1
[17:28:37] SQL (16.6ms) INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "failed_attempts", "last_sign_in_at", "last_sign_in_ip", "locale", "locked_at", "remember_created_at", "reset_password_sent_at", "reset_password_token", "role", "sign_in_count", "unconfirmed_email", "unlock_token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21) RETURNING "id" [["confirmation_sent_at", Fri, 05 Oct 2012 16:28:38 UTC +00:00], ["confirmation_token", "a2XPMojypDn6uzzVAqcs"], ["confirmed_at", nil], ["created_at", Fri, 05 Oct 2012 16:28:38 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "[email protected]"], ["encrypted_password", "$2a$10$HnsOCZgVTaEg9bniVzBe7OKIvw4x5hdAqjwrCG14eQDCvSTz8mxdu"], ["failed_attempts", 0], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["locale", nil], ["locked_at", nil], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["role", 0], ["sign_in_count", 0], ["unconfirmed_email", nil], ["unlock_token", nil], ["updated_at", Fri, 05 Oct 2012 16:28:38 UTC +00:00]]
[17:28:37] Rendered devise/mailer/confirmation_instructions.html.erb (0.8ms)
[17:28:37]
Sent mail to ...
[17:28:37] (0.8ms) COMMIT
[17:28:37] Redirected to http://localhost:3000/en
[17:28:37] Completed 302 Found in 5050ms (ActiveRecord: 0.0ms)
[17:28:42]
Started GET "/en" for 127.0.0.1 at 2012-10-05 17:28:42 +0100
[17:28:42] Processing by PageController#index as HTML
[17:28:42] Parameters: {"locale"=>"en"}
[17:28:42] Completed 401 Unauthorized in 0ms
[17:28:42]
Started GET "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2012-10-05 17:28:42 +0100
[17:28:42] Processing by Devise::SessionsController#new as HTML
[17:28:42] Rendered devise/shared/_links.erb (0.9ms)
[17:28:42] Rendered devise/sessions/new.html.erb within layouts/application (6.8ms)
[17:28:42] Completed 200 OK in 22ms (Views: 20.0ms | ActiveRecord: 0.0ms)
在routes.rb中我有:
root :to => "page#index"
所以發生了什麼是的PageController#指數將用戶重定向到登錄所以問題歸結爲如何僅此免除:的authenticate_user!在應用程序控制器中。
分辨率
所以感謝jibiel和this question答案是:
class PageController < ApplicationController
skip_before_filter :authenticate_user!
end
Simples!
謝謝。恐怕這不起作用。它的行爲方式完全一樣。我嘗試重新啓動服務器並將該線路移至應用程序控制器的最頂端。我已經在這個問題中提供了更多細節,以防這種情況的發生 –
然後請提供禮貌行動的日誌。我認爲這是像開機POST「/用戶」...處理由RegistrationsController#創建爲HTML。需要知道認證失敗的地方。這只是重定向,困擾你嗎?用戶是否正確創建了該案例? – jibiel
這很有幫助。我已經發布了顯示控制器操作的日誌:authenticate_user! –