未定义的局部变量或方法`root_path'用于#&lt;#<class:0xc0d0c44>:0xc0be918&gt;

时间:2016-09-29 18:38:54

标签: ruby-on-rails devise ruby-on-rails-5 devise-confirmable

我正在尝试使用Devise可验证的电子邮件,但现在出现错误并且它不起作用(在更改之前,它运行良好)。

如果有人能帮我识别它,我会很感激。

我正在尝试:http://www.bogotobogo.com/RubyOnRails/RubyOnRails_Devise_Authentication_Sending_Confirmation_Email.php

注册#name中的NameError

#&lt;#:0xc0be918&gt;的未定义局部变量或方法`root_path' 你的意思是? font_path

在视图标记中,尝试注册后:

 <li><%= link_to "Start", root_path %></li>

在路线中:

Rails.application.routes.draw do

   devise_for :usuarios, controllers: {registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks"}

   root 'welcome#index'
   get "welcome/index"

   get ':controller(/:action(/:id))(.:format)'
   post ':controller(/:action(/:id))(.:format)'

end

app/views/devise/mailer/confirmation_instructions.html.erb:12:in `_app_views_devise_mailer_confirmation_instructions_html_erb___614633226_101093210'
app/controllers/registrations_controller.rb:6:in `create'

rake routes

                             Prefix Verb     URI Pattern                                Controller#Action
                new_usuario_session GET      /usuarios/sign_in(.:format)                devise/sessions#new
                    usuario_session POST     /usuarios/sign_in(.:format)                devise/sessions#create
            destroy_usuario_session DELETE   /usuarios/sign_out(.:format)               devise/sessions#destroy
                   usuario_password POST     /usuarios/password(.:format)               devise/passwords#create
               new_usuario_password GET      /usuarios/password/new(.:format)           devise/passwords#new
              edit_usuario_password GET      /usuarios/password/edit(.:format)          devise/passwords#edit
                                    PATCH    /usuarios/password(.:format)               devise/passwords#update
                                    PUT      /usuarios/password(.:format)               devise/passwords#update
        cancel_usuario_registration GET      /usuarios/cancel(.:format)                 registrations#cancel
               usuario_registration POST     /usuarios(.:format)                        registrations#create
           new_usuario_registration GET      /usuarios/sign_up(.:format)                registrations#new
          edit_usuario_registration GET      /usuarios/edit(.:format)                   registrations#edit
                                    PATCH    /usuarios(.:format)                        registrations#update
                                    PUT      /usuarios(.:format)                        registrations#update
                                    DELETE   /usuarios(.:format)                        registrations#destroy
               usuario_confirmation POST     /usuarios/confirmation(.:format)           devise/confirmations#create
           new_usuario_confirmation GET      /usuarios/confirmation/new(.:format)       devise/confirmations#new
                                    GET      /usuarios/confirmation(.:format)           devise/confirmations#show
usuario_facebook_omniauth_authorize GET|POST /usuarios/auth/facebook(.:format)          omniauth_callbacks#passthru
 usuario_facebook_omniauth_callback GET|POST /usuarios/auth/facebook/callback(.:format) omniauth_callbacks#facebook
                               root GET      /                                          welcome#index
                      welcome_index GET      /welcome/index(.:format)                   welcome#index
                                    GET      /:controller(/:action(/:id))(.:format)     :controller#:action
                                    POST     /:controller(/:action(/:id))(.:format)     :controller#:action

环境:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  config.action_mailer.perform_deliveries = true

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    user_name:      ENV['uclave.cdcht'],
    password:       ENV[''],
    domain:         ENV['gmail'],
    address:       'smtp.gmail.com',
    port:          '587',
    authentication: :plain,
    enable_starttls_auto: true
  }

users = usuarios(西班牙语)

2 个答案:

答案 0 :(得分:3)

错误发生在邮件程序中。您不能在邮件程序中使用_path帮助程序(因为它会生成类似“/”的URL,这在单击邮件时无用)。

相反,您必须使用_url助手。假设您已设置root_url(应位于config.action_mailer.default_url_options = { host: 'example.com' }),则将邮件更改为使用config/application.rb即可。

答案 1 :(得分:0)

我遇到了类似的错误。但在我的情况下,我错误地评论了

    #root 'welcome#index'

在取消评论时,事情恢复正常。

    root 'welcome#index'