在我的控制器文件中:
class RegistrationsController < Devise::RegistrationsController
layout "devise"
before_action :check_url, only: [:new]
def create
attachments["logo.png"] = File.read("#{Rails.root}/public/assets/images/logo.png")
super
end
end
在我的视图文件中:
<%= image_tag attachments['logo.png'].url %>
之后我收到此错误,
未定义的局部变量或
的方法`附件'
答案 0 :(得分:2)
覆盖设计创建方法并不是一个好方法。你可以为此写回调。
class User < ActiveRecord::Base
# ...
after_create :send_admin_mail
def send_admin_mail
UserMailer.send_new_user_message(self).deliver
end
# ...
end
您的用户邮件应该看起来像
class UserMailer < ApplicationMailer
default from: 'notifications@example.com'
def send_new_user_message(user)
@user = user
@url = 'http://example.com/login'
attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')
mail(to: @user.email, subject: 'Welcome to My Awesome Site')
end
end