2016-06-30 2 views
0

저는 actionmailer를 처음 사용하기 때문에 ActionMailer가 제대로 작동하고 경로를 찾지 못하는 것 같아요. 제대로하고 있는지 잘 모르겠고 대부분의 자습서에서는 일반 사용자가 처음 계정을 만든 후 이메일Rails 4 ActionMailer 양식을 작성하여 이메일로 보내십시오.

내가하려는 것은 사용자가 양식을 통해 이메일을 생성하여 고객에게보기로 연결되는 링크가 포함 된 이메일을 보내어 인보이스를 볼 수 있도록 허용하는 것입니다. 여기

Missing template invoices/send_invoice_email, application/send_invoice_email은 내 양식입니다 ... 내 가정이

나의 현재 오류가 몇 가지 라우팅 문제로 인해하지만 이상한 점은 대신 메일러 컨트롤러의 내 컨트롤러에서 이메일 템플릿을 찾고 것을 이는 사용자가 이메일을 작성하는 데 사용합니다.

<%= bootstrap_form_tag url: '/send_invoice' do |l| %> 
    <%= l.hidden_field :invoice, value: @quote.id %> 
      <div class="input-group margin-bottom-20"> 
      <span class="input-group-addon" id="from"><i class="fa fa-envelope"> </i></span> 
      <%= l.text_field :from, hide_label: true, value: current_user.email %> 
      </div> 
      <div class="input-group margin-bottom-20"> 
      <span class="input-group-addon" id="to"><i class="fa fa-user"> </i></span> 
         <%= l.text_field :to, hide_label: true, value: @quote.client.contacts.first.email %> 
      </div> 
      <div class="input-group margin-bottom-20"> 
      <span class="input-group-addon" id="cc"><i class="fa fa-users"> </i></span> 
         <%= l.text_field :cc, hide_label: true, placeholder: "cc:" %> 
      </div> 
      <div class="input-group margin-bottom-20"> 
      <span class="input-group-addon" id="bcc"><i class="fa fa-users"> </i></span> 
         <%= l.text_field :bcc, hide_label: true, placeholder: "bcc:" %> 
      </div> 
      <div class="input-group margin-bottom-20"> 
      <span class="input-group-addon" id="subject"> <i class="fa fa-bullhorn"></i></span> 
        <%= l.text_field :subject, hide_label: true, placeholder: "Subject" %> 
      </div> 
      <div class="input-group margin-bottom-20"> 
      <span class="input-group-addon" id="message"> <i class="fa fa-comment"></i></span> 
        <%= l.text_area :message, hide_label: true, placeholder: "Message", rows:"5" %> 
      </div> 
      <%= l.submit "Send", class:'btn-u btn-u-blue btn-block' %> 
<% end %> 

내 송장 컨트롤러 내 컨트롤러 방법 (이것은 단지 쇼 컨트롤러, 견적을 인용 모델에서 생성됩니다) 여기

def send_invoice_email 
quote = Quote.find(params[:invoice]) 
InvoiceMailer.send_invoice_email(quote, params) 
end 

그리고 내 송장 메일러의 방법이다

def send_invoice_email(quote, params) 
@quote = quote 

mail(
to: current_user.email, 
from: params[:from], 
content_type: "text/html", 
body: params[:body], 
content_type: "text/html", 
subject: params[:subject], 
content_type: "text/html" 
) 
end 

답변

0

나는 몇 가지를 바꿨고 지금은 효과가있는 것으로 보인다. 현재 구성은 다음과 같습니다.

양식은 동일합니다. 내 송장 컨트롤러에서

지금은 내가 지금이 내 송장 메일러에서

def send_invoice_email 
    quote = Quote.find(params[:invoice]) 
    InvoiceMailer.invoice_email(quote, params).deliver_now 
end 

def invoice_email(quote, params) 
    @user = quote.user 
    @quote = quote 
    @message = params[:body] 
    mail to: params[:to], 
     from: @user.email, 
     body: @message, 
     subject: params[:subject], 
     content_type: "text/html" 
end 
관련 문제