首页 \ 问答 \ 保存记录后发送电子邮件 - rails(Send an email once record is saved - rails)

保存记录后发送电子邮件 - rails(Send an email once record is saved - rails)

每当用户创建并保存新记录时,我都会尝试向自己发送电子邮件。 我目前在我的控制器中保存了新记录:

UserMailer.notification_email().deliver

这在我的用户邮件中:

class UserMailer < ActionMailer::Base
  default from: "from@example.com"

  def notification_email()



    mail(:to => "admin@example.co.uk",
         :subject => "Test")
  end

end

我知道它应该传递一些参数我只是不确定是什么,加上我能找到的所有例子都会向每个用户发送电子邮件而不是静态电子邮件地址。


I'm trying to send an email to myself every time any user creates and saves a new record. I currently have this in the part of my controller that saves new records:

UserMailer.notification_email().deliver

And this in my user mailer:

class UserMailer < ActionMailer::Base
  default from: "from@example.com"

  def notification_email()



    mail(:to => "admin@example.co.uk",
         :subject => "Test")
  end

end

I'm aware it should probably pass some parameters I'm just not sure what, plus all the examples I can find send out emails to each user rather than a static email address.


原文:https://stackoverflow.com/questions/15389926
更新时间:2023-01-02 10:01

最满意答案

使用一个足够聪明的版本控制系统,可以在检入时忽略换行符,并在退房时使用正确的平台值。


Use a version control system that's smart enough to ignore line-endings on check-in, and use the correct value for the platform on check-out.

相关问答

更多
  • 你可以使用grep egrep -l $'\r'\$ * You could use grep egrep -l $'\r'\$ *
  • 根据http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression,=〜是: =~ 将根据扩展正则表达式进行检查 - 匹配时为TRUE 所以^#是一个扩展的正则表达式。 因为#不是扩展正则表达式中的特殊字符。 if的含义检查$1中的字符串不以#开头。 所以在命令行上 $ if [[ ! '#' =~ ^# ]]; then echo matches; else echo no match; ...
  • 使用一个足够聪明的版本控制系统,可以在检入时忽略换行符,并在退房时使用正确的平台值。 Use a version control system that's smart enough to ignore line-endings on check-in, and use the correct value for the platform on check-out.
  • 我设法通过向File.open的参数添加“b”来修复它 File.open("test.sh", 'wb') do |f| f.write("#!/bin/sh\n") f.write("echo hello\n") end IO类的文档说明如下: Mode | Meaning -----+-------------------------------------------------------- "b" | Binary file mode (may appear with ...
  • 在unix中,您只需使用$line .= '\n'; 因为\n是定义新行的字符。 In unix you would simply use $line .= '\n'; as \n is the character that defines a new line.
  • 这背后的主要原因是scv(源代码版本控制),其中改变行结束导致不必要的差异和冲突。 其次,我们通常在基于Unix的Linux上提供服务,Linux使用LF文件结尾。 第一个需要标准,第二个告诉你为什么要使用LF标准。 windows:CRLF = '\r\n' unix:LF = '\n' mac:CR = '\r' // macOS also changed to LF a long time ago btw. 更新:还要注意,尽管PHP和imo。 所有其他脚本语言 - 并不真正依 ...
  • 有一个选项,你使用的encode也适用于File.open : File.open('/tmp/foo', mode: 'w', crlf_newline: true) do |file| file.puts("alpha") file.puts("beta") end 该选项不仅以\r\n结束行,而且还将任何明确的\n转换为\r\n 。 所以这: file.puts("alpha\nbar") 将写入alpha\r\nbar\r\b There's an option for this, th ...
  • 是的,您必须在vimrc中添加分支以具有特定于机器/操作系统的设置。 这并不像听起来那么肮脏:单个if / ifelse / endif就足够了。 另一种方法是将您的计算机/操作系统特定设置保存在单独的非版本控制文件中:因为它非常本地化,您不需要在其他计算机/操作系统上传播其内容。 您可以将这些设置放在~/.vim/vimrc.local并明确地将此文件添加到.gitignore或~/.vimrc.local中的repo之外,并从您的vimrc中获取该文件。 Vim在Linux上使用Windows系列结尾时 ...
  • 从朋友的回复中发帖:首先你应该下载SciTE (你也可以下载其他文本编辑器)。 在SciTE ,您首先从视图菜单中启用行结束,然后在“选项”菜单下查看行结尾,调整行结束字符,然后(再次在“选项”下)转换行结束字符。 您应该选择LF选项。 Posting from a friend's response: First you should download SciTE (you can download other text editors as well). In SciTE, you'd first en ...
  • 我自己没试过,但是从xmlsave ,我可以看到两种可能性 xmlSaveToBuffer :保存到缓冲区,转换为CR / LF并自行写出来。 xmlSaveToIO :在回调函数中写入时注册一个iowrite回调并转换为CF / LF 也许,还有其他选择,但我还没有找到它们。 I haven't tried this myself, but from xmlsave, I can see two possibilities xmlSaveToBuffer: save to a buffer, conver ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)