保存记录后发送电子邮件 - 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
最满意答案
使用一个足够聪明的版本控制系统,可以在检入时忽略换行符,并在退房时使用正确的平台值。
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'\$ *
-
如果[[!(what is if [[ ! $1 =~ ^# ]]; in unix)[2022-04-07]
根据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行尾(Add unix end of line)[2021-12-15]
在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 ...