2014-12-16 2 views
0

나는 최근에 내 레일 응용 프로그램에 다국어 지원을 추가했습니다,하지만 지금은 내 모든 우편물은 ...경로 문제

class NotificationUserMailer < ActionMailer::Base 
    default from: '[email protected]' 

    def send_welcome_mail_to(user_id, password) 
    @user  = User.find(user_id) 
    @password = password 
    mail(to: @user.email, subject: 'Bienvenido a Timewarp') 
    end 
end 

가 도달 할 때마다 작동이 중지 여기

ActionView::Template::Error: No route matches {:action=>"new", :controller=>"devise/sessions"} missing required keys: [:locale]

내 코드

01 :
mail(to: @user.email, subject: 'Bienvenido a Timewarp') 

에 나는 다음과 같은 예외가 23,516,
class ApplicationController < ActionController::Base 
    before_action :set_locale 
    private 

    def default_url_options(options = {}) 
    {locale: I18n.locale} 
    end 

    private 

    def set_locale 
    I18n.locale = user_signed_in? ? current_user.language.to_sym : I18n.default_locale 
    end 
end 

환경

#development.rb 
config.action_mailer.default_url_options = { host: 'localhost', port: 3000, protocol: 'http', locale: I18n.locale } 
    config.action_mailer.asset_host = 'http://localhost:3000' 
    config.assets.raise_runtime_errors = false 
    config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" 
    # config.action_view.raise_on_missing_translations = true 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.default charset: 'utf-8' 
    config.action_mailer.smtp_settings = { 
    address: 'smtp.mandrillapp.com', 
    port: 587, 
    domain: Rails.application.secrets.domain_name, 
    enable_starttls_auto: true, 
    user_name: Rails.application.secrets.mandrill_username, 
    password: Rails.application.secrets.mandrill_api_key 
    } 

경로 :

Rails.application.routes.draw do 
    scope ':locale', locale: /#{I18n.available_locales.join('|')}/ do 
    devise_for :users 

    devise_scope :user do 
     authenticated :user do 
     root 'dashboard#show', as: :authenticated_root 
     end 

     unauthenticated do 
     root 'devise/sessions#new', as: :unauthenticated_root 
     end 
    end 

    root to: 'devise/sessions#new' 
    end 
    get '*path', to: redirect("/#{I18n.default_locale}/%{path}") 
    get '', to: redirect("/#{I18n.default_locale}") 
end 

사양 :

describe '#send_welcome_mail_to' do 
    it 'should send mail to user' do 
     user = create(:user) 
     expect { NotificationUserMailer.send_welcome_mail_to(user.id, user.password).deliver }.to change { ActionMailer::Base.deliveries.count }.by(1) 
    end 
    end 

은 ?? 내가 로케일 다른 곳 ApplicationController.rb을 설정해야합니까. 나는 지금 정말로 길을 잃었다. 어떤 도움이라도 좋을 것이다. .. 고마워!

+0

어디서부터 살펴 봐야할까요? : / – gustavoca

답변

0

필자는 로캘을 올바르게 설정하지 않은 "내 root_path"를 가지고있었습니다. 보기 밖의 경로를 만들었습니다. ...