覆盖引擎中的控制器(特别是在设计中)
我想在登录/注销时删除 Devise 的 set_flash_message,所以我创建了 我自己的session_controller,从devise的逐字复制。我将视图复制到应用程序/视图/会话,并更改了路线。现在,当我登录时,它会将我重定向回登录页面。 Rails 日志显示
Processing by SessionsController#new as HTML
当我使用内置会话控制器时不会显示哪些内容。有什么想法吗?
我可以在不覆盖控制器的情况下解决这个问题,但我怀疑我无论如何都会在某个时候这样做并遇到同样的问题。何塞不知道。我该如何解决这个问题?
Jay Levitt
app/controllers/sessions_controller.rb:与 /Users/jay/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.2.1/app/controllers/devise/sessions_controller.rb 相同。
config/routes.rb:
devise_for :users, :controllers => { :sessions => :sessions }
...
使用我的控制器副本进行rails输出:
Started POST "/users/sign_in" for 127.0.0.1 at 2011-04-07 16:15:54
-0400
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"o8JIe+jGu
+xiuuIbAZc6kg6aD6TKk86rKBydeFxLH40=",
"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]",
"remember_me"=>"0"}, "commit"=>"Sign in"}
PK and serial sequence (1.7ms) SELECT attr.attname, seq.relname
FROM pg_class seq,
pg_attribute attr,
pg_depend dep,
pg_namespace name,
pg_constraint cons
WHERE seq.oid = dep.objid
AND seq.relkind = 'S'
AND attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND cons.contype = 'p'
AND dep.refobjid = '"badges_users"'::regclass
PK and custom sequence (0.8ms) SELECT attr.attname,
CASE
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
substr(split_part(def.adsrc, '''', 2),
strpos(split_part(def.adsrc, '''', 2), '.')+1)
ELSE split_part(def.adsrc, '''', 2)
END
FROM pg_class t
JOIN pg_attribute attr ON (t.oid = attrelid)
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
WHERE t.oid = '"badges_users"'::regclass
AND cons.contype = 'p'
AND def.adsrc ~* 'nextval'
Completed in 101ms
Processing by SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"o8JIe+jGu
+xiuuIbAZc6kg6aD6TKk86rKBydeFxLH40=",
"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]",
"remember_me"=>"0"}, "commit"=>"Sign in"}
SQL (0.9ms) SELECT a.attname, format_type(a.atttypid,
a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Rendered devise/shared/_links.erb (1.6ms)
Rendered sessions/new.html.erb within layouts/devise/sessions (9.1ms)
Completed 200 OK in 162ms (Views: 13.4ms | ActiveRecord: 4.8ms)
使用内置控制器进行rails输出:
Started POST "/users/sign_in" for 127.0.0.1 at 2011-04-08 10:41:35 -0400
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"m3gKBQM8We9oHvsLjkPA8O/wQEJeZibRtY0tDgqZHxk=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
PK and serial sequence (1.8ms) SELECT attr.attname, seq.relname
FROM pg_class seq,
pg_attribute attr,
pg_depend dep,
pg_namespace name,
pg_constraint cons
WHERE seq.oid = dep.objid
AND seq.relkind = 'S'
AND attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND cons.contype = 'p'
AND dep.refobjid = '"badges_users"'::regclass
PK and custom sequence (0.7ms) SELECT attr.attname,
CASE
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
substr(split_part(def.adsrc, '''', 2),
strpos(split_part(def.adsrc, '''', 2), '.')+1)
ELSE split_part(def.adsrc, '''', 2)
END
FROM pg_class t
JOIN pg_attribute attr ON (t.oid = attrelid)
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
WHERE t.oid = '"badges_users"'::regclass
AND cons.contype = 'p'
AND def.adsrc ~* 'nextval'
SQL (0.7ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
SQL (0.6ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
SQL (0.1ms) BEGIN
AREL (0.3ms) UPDATE "users" SET "last_sign_in_at" = '2011-04-08 13:12:42.161090', "current_sign_in_at" = '2011-04-08 14:41:35.486567', "sign_in_count" = 17, "updated_at" = '2011-04-08 14:41:35.487136' WHERE "users"."id" = 6
SQL (0.3ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 302ms
I want to remove Devise's set_flash_message on signin/signout, so I created
my own sessions_controller, copied verbatim from devise's. I copied the view over to app/views/sessions, and changed the route. Now, when I sign in, it redirects me back to the sign in page. The rails log shows
Processing by SessionsController#new as HTML
which doesn't show up when I use the built-in session controller. Any ideas?
I can work around this without overriding the controller, but I suspect I'll want to do that anyway at some point and hit this same problem. Jose has no idea. How can I troubleshoot this?
Jay Levitt
app/controllers/sessions_controller.rb: Same as /Users/jay/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.2.1/app/controllers/devise/sessions_controller.rb.
config/routes.rb:
devise_for :users, :controllers => { :sessions => :sessions }
...
rails output using my copy of controller:
Started POST "/users/sign_in" for 127.0.0.1 at 2011-04-07 16:15:54
-0400
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"o8JIe+jGu
+xiuuIbAZc6kg6aD6TKk86rKBydeFxLH40=",
"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]",
"remember_me"=>"0"}, "commit"=>"Sign in"}
PK and serial sequence (1.7ms) SELECT attr.attname, seq.relname
FROM pg_class seq,
pg_attribute attr,
pg_depend dep,
pg_namespace name,
pg_constraint cons
WHERE seq.oid = dep.objid
AND seq.relkind = 'S'
AND attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND cons.contype = 'p'
AND dep.refobjid = '"badges_users"'::regclass
PK and custom sequence (0.8ms) SELECT attr.attname,
CASE
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
substr(split_part(def.adsrc, '''', 2),
strpos(split_part(def.adsrc, '''', 2), '.')+1)
ELSE split_part(def.adsrc, '''', 2)
END
FROM pg_class t
JOIN pg_attribute attr ON (t.oid = attrelid)
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
WHERE t.oid = '"badges_users"'::regclass
AND cons.contype = 'p'
AND def.adsrc ~* 'nextval'
Completed in 101ms
Processing by SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"o8JIe+jGu
+xiuuIbAZc6kg6aD6TKk86rKBydeFxLH40=",
"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]",
"remember_me"=>"0"}, "commit"=>"Sign in"}
SQL (0.9ms) SELECT a.attname, format_type(a.atttypid,
a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Rendered devise/shared/_links.erb (1.6ms)
Rendered sessions/new.html.erb within layouts/devise/sessions (9.1ms)
Completed 200 OK in 162ms (Views: 13.4ms | ActiveRecord: 4.8ms)
rails output using the built-in controller:
Started POST "/users/sign_in" for 127.0.0.1 at 2011-04-08 10:41:35 -0400
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"m3gKBQM8We9oHvsLjkPA8O/wQEJeZibRtY0tDgqZHxk=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
PK and serial sequence (1.8ms) SELECT attr.attname, seq.relname
FROM pg_class seq,
pg_attribute attr,
pg_depend dep,
pg_namespace name,
pg_constraint cons
WHERE seq.oid = dep.objid
AND seq.relkind = 'S'
AND attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND cons.contype = 'p'
AND dep.refobjid = '"badges_users"'::regclass
PK and custom sequence (0.7ms) SELECT attr.attname,
CASE
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
substr(split_part(def.adsrc, '''', 2),
strpos(split_part(def.adsrc, '''', 2), '.')+1)
ELSE split_part(def.adsrc, '''', 2)
END
FROM pg_class t
JOIN pg_attribute attr ON (t.oid = attrelid)
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
WHERE t.oid = '"badges_users"'::regclass
AND cons.contype = 'p'
AND def.adsrc ~* 'nextval'
SQL (0.7ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
SQL (0.6ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
SQL (0.1ms) BEGIN
AREL (0.3ms) UPDATE "users" SET "last_sign_in_at" = '2011-04-08 13:12:42.161090', "current_sign_in_at" = '2011-04-08 14:41:35.486567', "sign_in_count" = 17, "updated_at" = '2011-04-08 14:41:35.487136' WHERE "users"."id" = 6
SQL (0.3ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 302ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想自定义 devise 使用的消息,只需编辑 devise.en.yml 文件
config/locales/devise.en.yml
If you are just wanting to customize the messages that devise uses, just edit the devise.en.yml file
config/locales/devise.en.yml