简体   繁体   中英

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. On one hand, I want to send confirmation_instruction mail with one template for main_app. On the other hand, I want to send confirmation_instruction mail with another template for rails engine. Both view use the same model "Account". Any ideas please help!

Add a new layout as you like called '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 :-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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