ruby - Send an object using pry? -


i trying send object (user) notificationsmailer this:

pry(main)>notificationsmailer.welcome_facebook_user({:password=>'123',:email=>'as453now@gmail.com',:basic_profile=>{:name=>'samir'}}).deliver 

but got error:

actionview::template::error: undefined method `basic_profile' #<hash:0x0000000786d588> /app/app/views/notifications_mailer/welcome_facebook_user.html.haml:2:in `block in _app_views_notifications_mailer_welcome_facebook_user_html_haml__4104442834642741128_62933320' 

notificationsmailer.welcome_facebook_user:

  def welcome_facebook_user(user)     @user = user     puts "sent welcome_facebook_user to:"     puts user[:email]     mail(:to=>user[:email], :subject => "welcome!")   end 

my template:

=content_for :title   welcome, #{@user.basic_profile.name unless @user.basic_profile.nil?} 

in real world:

user.rb

class user < refinery::core::basemodel has_one :basic_profile 

but, want test using pry, how send such user object? why attempt failed?

you using hashes should using objects create object (i assuming mass-assigment turned off default) do:

basic_profile = basicprofile.new basic_profile.name = 'samir' user = user.new user.password = '123' user.email = 'aba@gmail.com' user.basic_profile = basic_profile notificationsmailer.welcome_facebook_user(user).deliver 

or turn mass-assign off , do

notificationsmailer.welcome_facebook_user(user.new({:password=>'123',:email=>'as453now@gmail.com',:basic_profile=>basicprofile.new({:name=>'samir'})})).deliver 

Comments