简体   繁体   English

为同一模型自定义Devise邮件模板路径

[英]Customize Devise mail template path for the same model

I am developing a rail application which include a rail engine. 我正在开发包括铁路引擎在内的铁路应用。 I use devise gem for account authentication. 我使用devise gem进行帐户身份验证。 On one hand, I want to send confirmation_instruction mail with one template for main_app. 一方面,我想发送带有一个main_app模板的confirmation_instruction邮件。 On the other hand, I want to send confirmation_instruction mail with another template for rails engine. 另一方面,我想发送带有另一个Rails引擎模板的Confirmation_instruction邮件。 Both view use the same model "Account". 这两个视图使用相同的模型“帐户”。 Any ideas please help! 任何想法请帮忙!

Add a new layout as you like called 'foo.html.erb' 根据需要添加新的布局,称为“ foo.html.erb”

In the main controller add the following: 在主控制器中添加以下内容:

layout "foo", :only => [ :index, :show ]

You can specify the layout for a specific action using: 您可以使用以下命令指定特定操作的布局:

def new 
 render(:layout => "layouts/application")
end

Define another layout for different action in a controller. 为控制器中的不同动作定义另一个布局。 It might be that adding another 可能是添加了另一个

layout "standard", :only => [ :new, :edit ] 

might work... 可能有效...

and also try this way:- 并尝试这种方式:

class MyController < ApplicationController

 def foo
   @model = Bar.first
   respond_to do |format|
    format.html {render :layout => 'application'}
    format.html.phone {render :layout => 'phone'}
    format.html.tablet {render :layout => 'tablet'}
   end
 end

end

In Rails 4.1 it is recently include :- 在Rails 4.1中,它最近包括

class ApplicationController < ActionController::Base
 before_action :detect_device_variant

 private

  def detect_device_variant
    case request.user_agent
    when /iPad/i
      request.variant = :tablet
    when /iPhone/i
      request.variant = :phone
    end
  end
end

class PostController < ApplicationController
 def show
  @post = Post.find(params[:id])

  respond_to do |format|
    format.json
    format.html               # /app/views/posts/show.html.erb
    format.html.phone         # /app/views/posts/show.html+phone.erb
    format.html.tablet do
      @show_edit_link = false
    end
  end
 end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM