2013-05-06 2 views
0

Я пытаюсь отправить объект (пользователя) к NotificationsMailer так:Отправка объекта с помощью pry?

pry(main)>NotificationsMailer.welcome_facebook_user({:password=>'123',:email=>'[email protected]',:basic_profile=>{:name=>'Samir'}}).deliver 

Но я получил эту ошибку:

ActionView::Template::Error: undefined method `basic_profile' for #<Hash:0x0000000786d588> 
from /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 

Мой шаблон :

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

В реальном мире:

User.rb

class User < Refinery::Core::BaseModel 
has_one :basic_profile 

Но я хочу, чтобы проверить его с помощью Поддеть, как отправить такой объект пользователя? почему моя попытка не удалась?

ответ

0

Вы используете хэши, но вы должны использовать объекты для создания объекта (я предполагаю, что массовый распайка выключен, как по умолчанию) делать:

basic_profile = BasicProfile.new 
basic_profile.name = 'Samir' 
user = User.new 
user.password = '123' 
user.email = '[email protected]' 
user.basic_profile = basic_profile 
NotificationsMailer.welcome_facebook_user(user).deliver 

или разворачивать массовое назначение и выполнять

NotificationsMailer.welcome_facebook_user(User.new({:password=>'123',:email=>'[email protected]',:basic_profile=>BasicProfile.new({:name=>'Samir'})})).deliver 
0

Попробуйте

> @user = User.create!(password: "123", email: "[email protected]") 
> @user.basic_profile.name = "Samir" 
> NotificationsMailer.welcome_facebook_user(@user).deliver 
Смежные вопросы