Ruby on Rails:从显示页面发送电子邮件 [英] Ruby on Rails: Send email from show page

查看:99
本文介绍了Ruby on Rails:从显示页面发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Rails菜鸟,在从显示页面发送电子邮件时遇到问题。那里有一些联系表单教程,但找不到从显示页面之类的页面发送电子邮件的地方。我相信自己的路线有很多错误。在模型中,我声明用户具有多个促销,并且在促销显示页面上,我要允许current_user向@user发送电子邮件。

I am a Rails noob and have a problem sending an email from a show page. There are several contact form tutorials out there but I cannot find one where I send an email from a page like a 'show' page. I have big errors in my routes I believe. In the model I state that Users have several Promotions and on the promotions show page I want to allow the current_user to send an email to @user.

这里是应用程序/邮件程序/quote_mailer.rb

here is app/mailers/quote_mailer.rb

class QuoteMailer < ActionMailer::Base
  default :from => "tim@example.com"

  def quote_mail(promotion)
    @user = user
    mail(:to => user.email, :subject => "You have an inquiry homeboy!")
  end 
end

在promotions_controller中,我把我认为这可能是错误的操作:

In promotions_controller I put this action which I think might be wrong:

def quotedeliver
  QuoteMailer.quote_mail.deliver
  flash[:notice] = 'report sent!'
  redirect_to root_path # or wherever
end

这是我用来发送电子邮件的表格(:url可能是错误的,但我不知道它的外观)

Here is the form that I use to send the email (the :url is probably wrong but I dont know how it should look)

<%= form_for quote_mail, :url => quotedeliver_promotion_path(promotion), :html => {:method => :put } do |f| %>
  <%= f.text_area :body %>
  <%= f.submit %>
<% end %>

我希望对此有所帮助。我已经在stackoverflow上找不到类似的东西了,我已经尝试了好几天了。谢谢!

I would love some help with this. I cannot find anything like it on stackoverflow, I have been trying for days. Thank you!

推荐答案

您可能会丢失config / routes.rb中的路由

You are probably missing the route in config/routes.rb

您可以将其定义为

post '/quotedeliver_promotion' => 'promotions#quotedeliver', :as => quotedeliver_promotion

请注意,quotedeliver必须重写quote_deliver以遵循ruby语法约定。致电

Note that quotedeliver has to be rewritten quote_deliver to follow ruby syntax conventions. When you call

QuoteMailer.quote_mail.deliver

您没有提供参数,因此请尝试

You are not giving the parameter, so try this

QuoteMailer.quote_mail(current_user).deliver

并使用

def quote_mail(user)
  mail ....
end

你们都很好

这篇关于Ruby on Rails:从显示页面发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆