生产环境下邮件发送器中的Rails4模板错误。

7

在我的生产环境中,我一直收到这个错误:

ActionView::Template::Error: undefined method `protocol' for nil:NilClass

我无法确定我的模板中出现了哪个错误,有人可以帮助我找出问题吗?

代码更新

完整代码:Pastebin

我剪掉了可能引起问题的区域:

<tr>
      <td class="eHeader" style="">
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="">
          <tr>
              <td class="eHeader" style="">
                <table width="100%" border="0" cellpadding="0" cellspacing="0" style="">
                  <tr>
                    <td class="eHeaderLogo" style="">
                        <a href="#" style="">
                            <img class="imageFix" src="<%= image_url('crewnetlogo-white.png') %>" width="200" height="48" alt="Crewnet" style="">
                        </a>
                    </td>
                    <!-- end .eHeaderLogo-->
                    <td class="eHeaderOptions" style="">

                    </td>
                    <!-- end .eHeaderOptions--> 
                  </tr>
                </table>
                    </td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
      <td>
        <h1>
        <span>
            Du er blevet tildelt <%= @workplace.name %>
        </span>
        </h1>
          <div class="bannerLink">
            <a href="#" style="">
            <img src="<%= image_url "app.png" %>" alt="Crewnet" width="512" height="194" style="">
            </a>
          </div>
        </td>
        <!-- end .highlight--> 
      </tr>

    <tr>
      <td class="eBody bottomLine" style="">
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="entryBox" style="">
          <tr>
            <td class="width132 pdBt16" style="">
            <a href="#" style="">
            <img src="<%= image_url "file_icon.gif" %>" width="116" height="116" alt="File" style="">
            </a>
            </td>
            <td class="alignLeft" style="">
              <p style=""> 
                Hej <%= @user.name %>!<br>
                Du har fået tildelt <%= @workplace.name %> som ansvarsområde. <br>
                For mere info log på <a href="<%= workplace_url(@workplace) %>">CrewNet | <%= @workplace.name %></a>.
              </p>
              <p style=""> 
                Skulle du have nogle spørgsmål, kan du kontakte supporten på <a href="mailto:support@crewnet.dk">support@crewnet.dk</a>.

                <br>
                <br>
                Teamet bag CrewNet.dk
              </p>
              </td>
          </tr>
        </table>
        </td>
      <!-- end .eBody--> 
    </tr>

邮件发送器

class SupervisorMailer < ActionMailer::Base
  default from: "support@crewnet.dk"

    def assigned(user, workplace)
      @user = User.find(user)
      @workplace = Workplace.find(workplace)

      mail to: @user.email, subject: "Du er ansvarlig for #{@workplace.name}."
    end
end

production.rb

config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name, :protocol => "http" }
config.action_mailer.asset_host =  Rails.application.secrets.domain_name

环境变量

secrets.domain_name = crewnet.dk

1
请发布您遇到错误的相关代码。 - Pavan
请粘贴您的邮件和模板代码。 - Rajdeep Singh
1个回答

9

可能与url构建有关。你的production.rb文件中是否有asset_host设置?也许你需要向asset_host添加协议。

Rails.application.configure do
  ...
  config.action_mailer.asset_host = 'http://example.com'
  ...
end

1
我发现问题确实出在action_mailer.asset_host上。我手动添加了主机名,而不是从环境变量中获取它。 - Mads E
1
我现在遇到的问题是,我的图像URL为http://crewnet.dk/asset=picname.jpg而不是http://crewnet.dk/asset/picname.jpg。 - Mads E

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接