MailView 언어 전환 지원
MailView 소개 
Rails 메일을 보내지 않아도 모두 한눈에 볼 수 있습니다MailView. 매우 편리합니다.Gemfile에 다음을 추가합니다.
Gemfilegem 'mail_view', require: false
bundle install가 config/routes.rb에 설치됩니다.
config/routes.rbMyApp::Application.routes.draw do
  if Rails.env.development?
    mount UserMailerPreview => 'user_mailer_preview'
  end
end
일반적인 설정은 이렇다.
lib/user_mailer_preview.rbrequire 'mail_view'
class UserMailerPreview < MailView
  # わかりやすい用にメールのアクション名と同じ名前でexport
  def mail_action
    UserMailer.mail_action
  end
end
이렇게 index가 나타나면
 
링크를 클릭하면 메일 내용이 이런 느낌으로 나온다.
 
언어 전환 지원 
MailView가 현재의 Params와 쿠키를 제공하지 않기 때문에 나는 매우 놀랐다.
주의해야 할 것은 MailView 클래스call를 제외한 공공 방법은 모두 노선으로 식별된다는 것이다.
lib/user_mailer_preview.rbrequire 'mail_view'
class UserMailerPreview < MailView
  # わかりやすい用にメールのアクション名と同じ名前でexport
  def mail_action
    UserMailer.mail_action
  end
  def call(env)
    @request = Rack::Request.new(env)
    # パラメータかクッキーからlangを探す
    @lang = @request.params['lang'] || @request.cookies['lang']
    if new_lang = @lang
      # ActiveRecord::Baseのカラムメソッドがロードされてない時用
      u = User.new
      u.lang
      User.class_eval do
        # langメソッドをバックアップ
        alias _lang lang
        # new_langを返すように上書き
        define_method :lang do
          new_lang
        end 
      end 
    end 
    status, header, body = super(env)
    if @lang
      # langメソッドを元に戻す
      User.class_eval do
        alias lang _lang
      end
      # Cookieにlangをセット
      ::Rack::Utils.set_cookie_header!(header, 'lang', @lang)
    end 
    [status, header, body]
  end 
  protected
  # MailViewのindexページのパスを上書き
  def index_template_path
    File.join(__DIR__, 'user_mailer_preview/index.html.erb')
  end 
end
mail_view의 기본 인덱스가 복사되어 다음과 같은lang을 선택할 수 있습니다.
신경 쓸 게 아니라서 프레임 팀으로 실례했습니다.
lib/user_mailer_preview/index.html.erb<style>
  table {
    height: 100%;
    width: 100%;
    font-family: "Lucida Grande", sans-serif;
    font-size: 12px;
  }
  body {
    padding: 0;
    margin: 0;
    font-family: "Lucida Grande", sans-serif;
    font-size: 12px;
  }
  td {
    vertical-align: top;
  }
  .mail-index {
    width: 400px;
    padding: 10px 0;
  }
  .mail-index table {
    height: 0px;
  }
  .mail-index table td {
    border-bottom: solid 1px #CCC;
    padding: 2px;
  }
  iframe {
    width: 100%;
    height: 100%;
  }
</style>
<table>
  <tbody>
    <tr>
      <td class="mail-index">
        <table cellspacing="0" cellpadding="0">
          <tbody>
            <% links.each do |name, link| %>
              <tr>
                <td><a href="<%= link %>" target="FRM"><%= name %></a></td>
                <td><a href="<%= link + '?lang=en' %>" target="FRM">En</a></td>
                <td><a href="<%= link + '?lang=ja' %>" target="FRM">Ja</a></td>
              </tr>
            <% end %>
          </tbody>
        </table>
      </td>
      <td>
        <iframe src=""
          width="300" height="250" name="FRM"
          scrolling="auto" frameborder="1">
        </iframe>
      </td>
    </tr>
  </tbody>
</table>
이렇게 프레임 위에서 전환할 수 있다.
언어의 전환도 원활하다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(MailView 언어 전환 지원), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/dtaniwaki/items/76c4f9c4c8d21679ae91
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
gem 'mail_view', require: false
MyApp::Application.routes.draw do
  if Rails.env.development?
    mount UserMailerPreview => 'user_mailer_preview'
  end
end
require 'mail_view'
class UserMailerPreview < MailView
  # わかりやすい用にメールのアクション名と同じ名前でexport
  def mail_action
    UserMailer.mail_action
  end
end
MailView가 현재의 Params와 쿠키를 제공하지 않기 때문에 나는 매우 놀랐다.
주의해야 할 것은 MailView 클래스
call를 제외한 공공 방법은 모두 노선으로 식별된다는 것이다.lib/user_mailer_preview.rb
require 'mail_view'
class UserMailerPreview < MailView
  # わかりやすい用にメールのアクション名と同じ名前でexport
  def mail_action
    UserMailer.mail_action
  end
  def call(env)
    @request = Rack::Request.new(env)
    # パラメータかクッキーからlangを探す
    @lang = @request.params['lang'] || @request.cookies['lang']
    if new_lang = @lang
      # ActiveRecord::Baseのカラムメソッドがロードされてない時用
      u = User.new
      u.lang
      User.class_eval do
        # langメソッドをバックアップ
        alias _lang lang
        # new_langを返すように上書き
        define_method :lang do
          new_lang
        end 
      end 
    end 
    status, header, body = super(env)
    if @lang
      # langメソッドを元に戻す
      User.class_eval do
        alias lang _lang
      end
      # Cookieにlangをセット
      ::Rack::Utils.set_cookie_header!(header, 'lang', @lang)
    end 
    [status, header, body]
  end 
  protected
  # MailViewのindexページのパスを上書き
  def index_template_path
    File.join(__DIR__, 'user_mailer_preview/index.html.erb')
  end 
end
mail_view의 기본 인덱스가 복사되어 다음과 같은lang을 선택할 수 있습니다.신경 쓸 게 아니라서 프레임 팀으로 실례했습니다.
lib/user_mailer_preview/index.html.erb
<style>
  table {
    height: 100%;
    width: 100%;
    font-family: "Lucida Grande", sans-serif;
    font-size: 12px;
  }
  body {
    padding: 0;
    margin: 0;
    font-family: "Lucida Grande", sans-serif;
    font-size: 12px;
  }
  td {
    vertical-align: top;
  }
  .mail-index {
    width: 400px;
    padding: 10px 0;
  }
  .mail-index table {
    height: 0px;
  }
  .mail-index table td {
    border-bottom: solid 1px #CCC;
    padding: 2px;
  }
  iframe {
    width: 100%;
    height: 100%;
  }
</style>
<table>
  <tbody>
    <tr>
      <td class="mail-index">
        <table cellspacing="0" cellpadding="0">
          <tbody>
            <% links.each do |name, link| %>
              <tr>
                <td><a href="<%= link %>" target="FRM"><%= name %></a></td>
                <td><a href="<%= link + '?lang=en' %>" target="FRM">En</a></td>
                <td><a href="<%= link + '?lang=ja' %>" target="FRM">Ja</a></td>
              </tr>
            <% end %>
          </tbody>
        </table>
      </td>
      <td>
        <iframe src=""
          width="300" height="250" name="FRM"
          scrolling="auto" frameborder="1">
        </iframe>
      </td>
    </tr>
  </tbody>
</table>
이렇게 프레임 위에서 전환할 수 있다.언어의 전환도 원활하다.
                Reference
이 문제에 관하여(MailView 언어 전환 지원), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/dtaniwaki/items/76c4f9c4c8d21679ae91텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)