English 中文(简体)
能够进入记录领域
原标题:Can t access field in record

我试图使用我的班子的子,但我却不断发现这一错误。

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
最佳回答

我认为,Sam所说的话确保你实际上将用户模式的事例纳入你的电文——发送功能。 扩大萨姆实例:

def message_sender(user)
   if user.class != User
       #your code
   else
       puts  Error: input is not a User Object 
   end
end

如果用户变量的通过不是类别用户,则该代码将打印错误。 红十字与红新月联会的确印刷了错误信息,即,如果你在申请中发出电文,问题很可能发生。 您通过有效的用户对电文表示反对。 所有的信贷都转给了Sam,用于回答。 (如果我不是一个新用户,我只想就他的职位发表评论)。

问题回答

Make sure user is actually an object.

def message_sender(user)
   if user
       #your code
   else
       puts  Error: User is nil 
   end
end




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签