ruby on Rails 中的设计错误

发布于 2024-12-07 08:00:17 字数 3412 浏览 0 评论 0原文

所以,我以前从未使用过 devise,并尝试通过 http://railscasts 在我的程序中实现它.com/episodes/209-introducing-devise。我安装了它,并像这个人一样逐字逐句安装了所有内容,然后当我尝试访问 http://localhost:3000 时/users/sign_up,我收到此错误:

 Routing Error

 No route matches [GET] "/users/sign_up"

这是我在进行 rake 路由时得到的结果:

new_user_session GET    /users/sign_in(.:format)              {:action=>"new", :controller=>"devise/sessions"}
    user_session POST   /users/sign_in(.:format)              {:action=>"create", :controller=>"devise/sessions"}
 destroy_user_session GET    /users/sign_out(.:format)             {:action=>"destroy", :controller=>"devise/sessions"}
        password POST   /users/password(.:format)             {:action=>"create", :controller=>"devise/passwords"}
    new_password GET    /users/password/new(.:format)         {:action=>"new", :controller=>"devise/passwords"}
   edit_password GET    /users/password/edit(.:format)        {:action=>"edit", :controller=>"devise/passwords"}
                 PUT    /users/password(.:format)             {:action=>"update", :controller=>"devise/passwords"}
                 POST   /users/registration(.:format)         {:action=>"create", :controller=>"devise/registrations"}
             new GET    /users/registration/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
            edit GET    /users/registration/edit(.:format)    {:action=>"edit", :controller=>"devise/registrations"}
                 PUT    /users/registration(.:format)         {:action=>"update", :controller=>"devise/registrations"}
                 DELETE /users/registration(.:format)         {:action=>"destroy", :controller=>"devise/registrations"}
       vote_post POST   /posts/:id/vote(.:format)             {:action=>"vote", :controller=>"posts"}
           posts GET    /posts(.:format)                      {:action=>"index", :controller=>"posts"}
                 POST   /posts(.:format)                      {:action=>"create", :controller=>"posts"}
        new_post GET    /posts/new(.:format)                  {:action=>"new", :controller=>"posts"}
       edit_post GET    /posts/:id/edit(.:format)             {:action=>"edit", :controller=>"posts"}
            post GET    /posts/:id(.:format)                  {:action=>"show", :controller=>"posts"}
                 PUT    /posts/:id(.:format)                  {:action=>"update", :controller=>"posts"}
                 DELETE /posts/:id(.:format)                  {:action=>"destroy", :controller=>"posts"}
            root        /                                     {:controller=>"users", :action=>"index"}

如果您观看视频,该人就可以访问该网址并且它可以正常工作。我注意到有一个 [GET] /users/registration/sign_up(.:format) 但没有像视频中的人那样的 [GET] /users/sign_up 。我有什么遗漏的吗?

ps

这是当我尝试转到上面列出的路线之一(用户/登录)时收到的错误:

 NoMethodError in Devise/registrations#new
 Showing /Users/davidfleischhauer/.rvm/gems/ruby-1.9.2-p290/gems/devise- 1.1.rc0/app/views/devise/registrations/new.html.erb where line #3 raised:

 undefined method `user_registration_path' for #<#<Class:0x007f85eafec758>:0x007f85eaf77ed0>

So, I have never used devise before and am trying to implement it in my program via http://railscasts.com/episodes/209-introducing-devise. I installed it and everything word for word as this guy did and then when I try and go to http://localhost:3000/users/sign_up, I get this error:

 Routing Error

 No route matches [GET] "/users/sign_up"

here is what I get when I do rake route:

new_user_session GET    /users/sign_in(.:format)              {:action=>"new", :controller=>"devise/sessions"}
    user_session POST   /users/sign_in(.:format)              {:action=>"create", :controller=>"devise/sessions"}
 destroy_user_session GET    /users/sign_out(.:format)             {:action=>"destroy", :controller=>"devise/sessions"}
        password POST   /users/password(.:format)             {:action=>"create", :controller=>"devise/passwords"}
    new_password GET    /users/password/new(.:format)         {:action=>"new", :controller=>"devise/passwords"}
   edit_password GET    /users/password/edit(.:format)        {:action=>"edit", :controller=>"devise/passwords"}
                 PUT    /users/password(.:format)             {:action=>"update", :controller=>"devise/passwords"}
                 POST   /users/registration(.:format)         {:action=>"create", :controller=>"devise/registrations"}
             new GET    /users/registration/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
            edit GET    /users/registration/edit(.:format)    {:action=>"edit", :controller=>"devise/registrations"}
                 PUT    /users/registration(.:format)         {:action=>"update", :controller=>"devise/registrations"}
                 DELETE /users/registration(.:format)         {:action=>"destroy", :controller=>"devise/registrations"}
       vote_post POST   /posts/:id/vote(.:format)             {:action=>"vote", :controller=>"posts"}
           posts GET    /posts(.:format)                      {:action=>"index", :controller=>"posts"}
                 POST   /posts(.:format)                      {:action=>"create", :controller=>"posts"}
        new_post GET    /posts/new(.:format)                  {:action=>"new", :controller=>"posts"}
       edit_post GET    /posts/:id/edit(.:format)             {:action=>"edit", :controller=>"posts"}
            post GET    /posts/:id(.:format)                  {:action=>"show", :controller=>"posts"}
                 PUT    /posts/:id(.:format)                  {:action=>"update", :controller=>"posts"}
                 DELETE /posts/:id(.:format)                  {:action=>"destroy", :controller=>"posts"}
            root        /                                     {:controller=>"users", :action=>"index"}

If you watch the video the guy is just able to go to that web address and it just works. I noticed that there is a [GET] /users/registration/sign_up(.:format) but no [GET] /users/sign_up like the guy in the video has. Is there something I am missing?

p.s.

this is the error I get when I try to go to one of the routes listed above (user/sign_in):

 NoMethodError in Devise/registrations#new
 Showing /Users/davidfleischhauer/.rvm/gems/ruby-1.9.2-p290/gems/devise- 1.1.rc0/app/views/devise/registrations/new.html.erb where line #3 raised:

 undefined method `user_registration_path' for #<#<Class:0x007f85eafec758>:0x007f85eaf77ed0>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水染的天色ゝ 2024-12-14 08:00:17

您必须使用 new_user_registration_path 才能创建指向注册页面的链接。您必须使用 new_user_session_path 才能创建登录链接。

You have to use new_user_registration_path in order to create a link to the sign up page. You have to use new_user_session_path in order to create a link to sign_in.

橘味果▽酱 2024-12-14 08:00:17

请记住,该视频已有一年多了:)

如果您查看 生成路由的当前设备源,您会发现它显然不再创建“sign_up”路由——看起来注册路径是当前方法。

看起来您正在使用候选版本,这总是让我有点紧张,因为那是候选版本,不一定 100% 稳定——这可能解释了为什么使用默认模板不存在的路径变量。

Bear in mind the video is a year+ old :)

If you look at the current devise source where the routes are generated you'll see that it apparently no longer creates a "sign_up" route--looks like the registration paths are the current method.

It also looks like you're using a release candidate version, which always makes me a little nervous, since that's a release candidate and not necessarily 100% stable--which might explain why the default template is using a path variable that doesn't exist.

っ〆星空下的拥抱 2024-12-14 08:00:17

我想弄清楚为什么你使用 Devise 版本 1.1rc0 而不是最新的 gem 1.4.7?我有几个应用程序都运行这个最新版本,其中 sign_up 路径工作得很好。我建议更新到最新版本的 gem,然后重试。除此之外,我只能想到可能由 routes.rb 文件中的某些内容或您尝试覆盖设计注册控制器引起的问题。

I am trying to figure out why you are using Devise version 1.1rc0 and not the latest gem available which is 1.4.7? I have several applications all running this latest version in which the sign_up path works just fine. I would recommend updating to the latest version of the gem and try again. Outside of that, I can only think of problems that could be caused by something in your routes.rb file or if you are trying to override the Devise Registrations Controller.

海的爱人是光 2024-12-14 08:00:17

添加到routes.rb,这是:

devise_for :users do

  get'users/sign_out'=>'devise/sessions#destroy'

end

它用于sign_out

用于sign_up转到config/initializers/secret_token.rb并复制行:config.secret_token ='...'
并将其粘贴到 config/application.rb 中

add to routes.rb this is:

devise_for :users do

  get'users/sign_out'=>'devise/sessions#destroy'

end

it's for sign_out

for sign_up go to config/initializers/secret_token.rb and copy line: config.secret_token ='...'
and paste it in config/aplication.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文