小编Abh*_*nyu的帖子

如何在rails 3.0.3中设置邮件拦截器?

我使用的是rails 3.0.3,ruby 1.9.2-p180,mail(2.2.13).我试图设置邮件拦截器,但我收到以下错误

 /home/abhimanyu/Aptana_Studio_3_Workspace/delivery_health_dashboard_03/config/initializers/mailer_config.rb:16:in `<top (required)>': uninitialized constant DevelopmentMailInterceptor (NameError)
Run Code Online (Sandbox Code Playgroud)

我如何解决它?

我使用的代码如下所示:

config/initializer/mailer_config.rb

ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "secure.emailsrvr.com",
:port => '25',
:domain => "domain",
:user_name => "user_name",
:password => "password",
:authentication => :plain
Run Code Online (Sandbox Code Playgroud)

}

ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if  Rails.env.development?
Run Code Online (Sandbox Code Playgroud)

LIB /为development_mail_interceptor.rb

class DevelopmentMailInterceptor

  def self.delivering_email(message)
    message.to = "email"
  end

end
Run Code Online (Sandbox Code Playgroud)

提前致谢.

ruby actionmailer ruby-on-rails-3

24
推荐指数
2
解决办法
6427
查看次数

继承自Devise :: SessionsController的控制器中的自定义操作的路由

我有一个继承自Devise :: SessionsController的会话控制器:

class SessionsController < Devise::SessionsController

  skip_before_filter :authenticate_user!, :only => [:get_token]

  def create
   ....
  end

 def destroy
  ...
 end

 def get_token
   response.headers["app-key"] = form_authenticity_token()
   render :text=>'Token Set'
 end

end
Run Code Online (Sandbox Code Playgroud)

如上所示,我覆盖了创建和销毁操作,并添加了另一个名为get_token的操作.我为它添加了路线,如下所示:

的routes.rb

Application.routes.draw do

  devise_for :users, :controllers => { :sessions => "sessions" }, :path => "users",      :path_names => { :sign_in => 'login', :sign_out => 'logout',:confirmation => 'verification'}

  match 'get_token', :to => 'sessions#get_token'
Run Code Online (Sandbox Code Playgroud)

但是当我尝试访问get_token方法时,我得到以下错误信息;

[Devise] Could not find devise mapping for path "/get_token". 
Run Code Online (Sandbox Code Playgroud)

如何为get_token操作添加路由.

提前致谢

routing ruby-on-rails devise

9
推荐指数
1
解决办法
4019
查看次数