我有rails 4.1.6邮件程序预览的问题.
我希望在预览模式下看到附加的图像,但它不起作用.我认为这是不正确的
有我的代码:
邮件文件
class AppMailer < ActionMailer::Base
default from: "robot@mysite.com"
# AppMailer.test_mail.deliver
def test_mail
attachments.inline['rails.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'rails.png'))
mail(
to: 'my-email@gmail.com',
subject: "test letter",
template_path: "mailers",
template_name: "test"
)
end
end
Run Code Online (Sandbox Code Playgroud)
预览文件
class MailerPreview < ActionMailer::Preview
def app_mailer
AppMailer.test_mail
end
end
Run Code Online (Sandbox Code Playgroud)
模板文件
%p Hello, World!
%p= image_tag attachments['rails.png'].url
Run Code Online (Sandbox Code Playgroud)
当我去
/rails/mailers/mailer/app_mailer
Run Code Online (Sandbox Code Playgroud)
我看到预览页面,但图像不起作用.结果是html代码
<p>Hello, World!</p>
<p><img src="cid:544d1354a8aa0_fda8082dbf8258ca@admins-air.mail"></p>
Run Code Online (Sandbox Code Playgroud)
所以.我想,我应该找到一种方法来获取路径/到/文件而不是预览模式下的CID
(当我把信寄到我的邮箱时 - 信看起来不错)
我在预览模式下做错了什么?
这是我从旧数据库中移动数据的代码:
class Old < ActiveRecord::Base
establish_connection :old_version
self.abstract_class = true
class Recipe < self
set_table_name :recipes
has_many :uploaded_files, :as => :storage
end
class UploadedFile < self
set_table_name :uploaded_files
belongs_to :storage, :polymorphic => true
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行以下代码时
Old::Recipe.all.each do |recipe|
puts recipe.uploaded_files.to_sql
end
Run Code Online (Sandbox Code Playgroud)
它执行此SQL
SELECT `uploaded_files`.* FROM `uploaded_files` WHERE `uploaded_files`.`storage_id` = 38 AND `uploaded_files`.`storage_type` = 'Old::Recipe'
Run Code Online (Sandbox Code Playgroud)
问题是我得到:
`storage_type` = 'Old::Recipe'
Run Code Online (Sandbox Code Playgroud)
但是我需要:
`storage_type` = 'Recipe'
Run Code Online (Sandbox Code Playgroud)
如何更改多态关系的类?
doc for doc has_many没有给我一个答案.
我有一些测试课
TestKlass = (function() {
function TestKlass(value) {
this.value = value != null ? value : 'hello world';
console.log(this.value);
}
return TestKlass;
})();
x = new TestKlass;
x instanceof TestKlass; (gives true)
Run Code Online (Sandbox Code Playgroud)
我有新的空物
y = {}
y instanceof Object
Run Code Online (Sandbox Code Playgroud)
我能找到任何方法来为y设置任何属性,就像这样
y.__proto__ = x.__proto__
y.constructor.prototype = x.constructor.prototype
Run Code Online (Sandbox Code Playgroud)
为了得到这个结果
y instanceof TestKlass => true
Run Code Online (Sandbox Code Playgroud)
================================================== ==
UPD:
所以.我的主要目标 - 创建CLONE功能.现在我的解决方案适合我.请看这段代码:
JavaScript JS对象克隆
Object._clone = function(obj) {
var clone, property, value;
if (!obj || typeof obj !== 'object') {
return obj; …Run Code Online (Sandbox Code Playgroud) 当cap3尝试在我的FreeBSD服务器上执行命令时 - 我有错误,我的cap3任务不起作用
DEBUG [0bb99d53] Command: if test ! -d /home/web_server/data/www/capistrano/site/shared/dumps; then echo "Directory does not exist '/home/web_server/data/www/capistrano/site/shared/dumps'" 1>&2; false; fi
DEBUG [0bb99d53] if: Expression Syntax.
DEBUG [0bb99d53] fi: Command not found.
Run Code Online (Sandbox Code Playgroud)
我知道为什么 - 因为我的服务器默认使用csh shell
% echo $0
-csh
Run Code Online (Sandbox Code Playgroud)
以下cap3变量对我不起作用
set :shell, '/usr/local/bin/bash'
set :default_shell, '/usr/local/bin/bash'
Run Code Online (Sandbox Code Playgroud)
如何为cap3任务设置shell?
actionmailer ×1
capistrano3 ×1
class ×1
ecmascript-5 ×1
has-many ×1
instanceof ×1
javascript ×1
polymorphism ×1
shell ×1
sshkit ×1