我试图使用我的班子的子,但我却不断发现这一错误。
undefined method `suffix for nil:NilClass
电子邮件:rb
class MessageMailer < ActionMailer::Base
default :from => "noreply@cs.tsu.edu"
def message_sender(user)
@user = user
carrier= user.carrier
sms=user.telephone +carrier.suffix
attachments["smalltsulogo.png"] = File.read("#{Rails.root}/public/images/smalltsulogo.png")
mail(:to => "#{user.login} <#{user.email}>", :subject => "New Message from cs.tsu.edu")
mail(:to => "#{user.login} <#{sms}>", :subject => "New Message from cs.tsu.edu")
end
end
1. 创造移徙者
class CreateCarriers < ActiveRecord::Migration
def self.up
create_table :carriers do |t|
t.string :name
t.string :suffix
t.timestamps
end
end
def self.down
drop_table :carriers
end
end
承运人增加指数
class AddIndexToCarrier < ActiveRecord::Migration
def self.up
add_index :carriers, :suffix
end
def self.down
remove_index :carriers, :suffix
end
end