Here is code of two models which have 1 to 1 association
class User < ActiveRecord::Base
has_one :e_user
validates_presence_of :first_name
validates_presence_of :last_name
validates :password, presence: true, :length => { :minimum => 6}
validates_uniqueness_of :email, :message => ": This email is already registered!"
validates_presence_of :email
end
Below is second model:
class EUser < ActiveRecord::Base
belongs_to : user
end
When i go to rails console and get a User from db, by doing
a = User.where(:id => 1)
I get a user in a. Now I want to get the e_user associated with a(if any it should return it or return null), but i get error message when i type a.EUser in console, error is
NoMethodError: undefined method `EUser' for #<ActiveRecord::Relation:0x00000002ab5908>from /home/faraz/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.1/lib/active_record/relation.rb:459:in `method_missing'
from (irb):3
from /home/faraz/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /home/faraz/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /home/faraz/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Regards