使用Rails 3.2.13
和devise 2.2.3
,我有一个普通用户,可以登录并进入信息中心。当我使用设计创建不同的用户并使其成为单独的视图,控制器和模型时,它的行为方式不同。我甚至以与用户相同的方式为关联user1建模。现在我明白我错过了一些范围设计模型的东西,也阅读了文档,但不知怎的,我没有实现它。 user1注册正常,但在注册后,它会被重定向到家。
以下是一些细节,将在提出更多信息时提供:
devise_for :user1
match 'user1/sign_up' => 'user1#new'
match 'user1/dashboard' => 'user1#dashboard'
Started POST "/user1" for 127.0.0.1 at 2014-06-03 10:58:58 +0530
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"yjG8AroaqqhCeyW9IDMNYHPV4+brvbdA3IlFNdf4Ecw=", "user1"=>{"email"=>"abc@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.3ms) BEGIN
User1 Exists (48.8ms) SELECT 1 AS one FROM "user1" WHERE ""."email" = 'abc@gmail.com' LIMIT 1
user1 Load (25.8ms) SELECT "user1".* FROM "user1" WHERE "user1"."confirmation_token" = 'vzwnRygWM6HiPezPfPfq' LIMIT 1
SQL (70.6ms) INSERT INTO "user1" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "last_sign_in_at", "last_sign_in_ip", "name", "remember_created_at", "reset_password_sent_at", "reset_password_token", "role", "sign_in_count", "unconfirmed_email", "updated_at", "verified", "verified_by_admin") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) RETURNING "id" [["confirmation_sent_at", Tue, 03 Jun 2014 05:28:59 UTC +00:00], ["confirmation_token", "vzwnRygWM6HiPezPfPfq"], ["confirmed_at", nil], ["created_at", Tue, 03 Jun 2014 05:28:59 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "abc@gmail.com"], ["encrypted_password", "$2a$10$kwhkGjNd9ocZ3t.WUUZB4uGXFnpoDao9rHLD5rlEUR/iO0mVWQ1gS"], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["name", ""], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["role", nil], ["sign_in_count", 0], ["unconfirmed_email", nil], ["updated_at", Tue, 03 Jun 2014 05:28:59 UTC +00:00], ["verified", nil], ["verified_by_admin", nil]]
Rendered user1/mailer/confirmation_instructions.html.erb (0.8ms)
Sent mail to abc@gmail.com (63ms)
Date: Tue, 03 Jun 2014 10:58:59 +0530
From: notifications@filmzu.com
To: abc@gmail.com
Message-ID: <538d5d1b7df6a_12b040fc01814856@pc3.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
<p>You can confirm your account email through the link below:</p>
<p><a href="">Confirm my account</a></p>
Sent mail to abc@gmail.com (2ms)
Date: Tue, 03 Jun 2014 10:58:59 +0530
To: abc@gmail.com
Message-ID: <538d5d1b8d81d_12b040fc01814951@pc3.mail>
Subject: Sign Up Confirmation
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
(53.7ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 882ms (ActiveRecord: 0.0ms)
Started GET "/" for 127.0.0.1 at 2014-06-03 10:58:59 +0530
Processing by HomeController#index as HTML
Rendered application/_cta.html.erb (0.0ms)
Rendered home/index.html.erb within layouts/application (2.7ms)
Rendered application/_header.html.erb (0.5ms)
Rendered application/_footer.html.erb (0.8ms)
Completed 200 OK in 67ms (Views: 66.1ms | ActiveRecord: 0.0ms)
请指导我如何为user1实现相同的目标,以及如何将为用户开发的内容与user1相同。
答案 0 :(得分:0)
根据设计文档,您可以为模型创建范围路径。默认情况下,devise将首先查找范围的root_path,如果它不存在,它将重定向到默认的root。
范围根路径为:“#{devise_model_name} _root_path”
请考虑以下示例:
get 'user1/dashboard', :to => 'user1#dashboard', :as => :user1_root
有关设计文档的Controller filter and Helper部分的更多信息。
希望这有帮助!