user model
has_one :paying_user, :dependent => :destroy
paying_user model
set_primary_key :user_id
belongs_to :user
has_one :credit_card, :foreign_key => ‘user_id’, :dependent
=> :destroy
I can load and print <%= user.paying_user.credit_card %> ONCE and it works, if I reload the page I got:
undefined method `credit_card’ for #PayingUser:0xb7153378
log tail:
Processing MerchantController#rebill (for 127.0.0.1 at 2007-06-18
18:05:56) [GET]
Mon Jun 18 18:05:56 +0000 2007 (6124) Session ID:
f752e7e5c586cefc81b62a352d0cf6a9
Mon Jun 18 18:05:56 +0000 2007 (6124) Parameters:
{“action”=>“rebill”, “controller”=>“merchant”}
Mon Jun 18 18:05:56 +0000 2007 (6124) [4;35;1mUser Load Including
Associations (0.016470) [0m [0mSELECT users.id
AS t0_r0,
users.username
AS t0_r1, users.email
AS t0_r2, users.firstname
AS t0_r3, users.lastname
AS t0_r4, users.gender_id
AS t0_r5,
users.born_on
AS t0_r6, users.created_at
AS t0_r7,
users.expires_on
AS t0_r8, users.roles
AS t0_r9, users.hobbies
AS t0_r10, paying_users.user_id
AS t1_r0, paying_users.firstname
AS t1_r1, paying_users.lastname
AS t1_r2, paying_users.email
AS
t1_r3, paying_users.address1
AS t1_r4, paying_users.address2
AS
t1_r5, paying_users.city
AS t1_r6, paying_users.state_province
AS
t1_r7, paying_users.postal_code
AS t1_r8, paying_users.country
AS
t1_r9, paying_users.payment_type
AS t1_r10,
paying_users.phone_number
AS t1_r11, paying_users.auto_renew
AS
t1_r12 FROM users LEFT OUTER JOIN paying_users ON paying_users.user_id
= users.id WHERE (expires_on < ‘2007-06-18’ AND expires_on <>
‘2007-06-23’ AND auto_renew = 1) ORDER BY expires_on DESC [0m
Mon Jun 18 18:05:56 +0000 2007 (6124) [4;36;1mUser Load Including
Associations (0.000212) [0m [0;1mSELECT users.id
AS t0_r0,
users.username
AS t0_r1, users.email
AS t0_r2, users.firstname
AS t0_r3, users.lastname
AS t0_r4, users.gender_id
AS t0_r5,
users.born_on
AS t0_r6, users.created_at
AS t0_r7,
users.expires_on
AS t0_r8, users.roles
AS t0_r9, users.hobbies
AS t0_r10, paying_users.user_id
AS t1_r0, paying_users.firstname
AS t1_r1, paying_users.lastname
AS t1_r2, paying_users.email
AS
t1_r3, paying_users.address1
AS t1_r4, paying_users.address2
AS
t1_r5, paying_users.city
AS t1_r6, paying_users.state_province
AS
t1_r7, paying_users.postal_code
AS t1_r8, paying_users.country
AS
t1_r9, paying_users.payment_type
AS t1_r10,
paying_users.phone_number
AS t1_r11, paying_users.auto_renew
AS
t1_r12 FROM users LEFT OUTER JOIN paying_users ON paying_users.user_id
= users.id WHERE (expires_on = ‘2007-06-18’ AND auto_renew = 1) ORDER
BY expires_on DESC [0m
Mon Jun 18 18:05:56 +0000 2007 (6124) Rendering within layouts/
application
Mon Jun 18 18:05:56 +0000 2007 (6124) Rendering merchant/rebill
Mon Jun 18 18:05:56 +0000 2007 (6124)
ActionView::TemplateError (undefined method `credit_card’ for
#PayingUser:0xb7153378) on line #15 of app/views/merchant/
rebill.rhtml:
12:
13:
14:
15: <% user.auth().message %>
16:
17: <%= user.paying_user.credit_card %>
18:
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1860:in method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ associations/association_proxy.rb:123:in
send’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
associations/association_proxy.rb:123:in method_missing' #{RAILS_ROOT}/app/models/user.rb:161:in
format_credit_card’
#{RAILS_ROOT}/app/models/user.rb:234:in auth' #{RAILS_ROOT}/app/views/merchant/rebill.rhtml:15:in
_run_rhtml_47app47views47merchant47rebill46rhtml’
#{RAILS_ROOT}/app/views/merchant/rebill.rhtml:11:in each' #{RAILS_ROOT}/app/views/merchant/rebill.rhtml:11:in
_run_rhtml_47app47views47merchant47rebill46rhtml’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/
base.rb:326:in send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/ base.rb:326:in
compile_and_render_template’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/
base.rb:301:in render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/ base.rb:260:in
render_file’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:806:in render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:711:in
render_with_no_layout’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/layout.rb:247:in render_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/benchmarking.rb:50:in
render’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/benchmarking.rb:50:in
render’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:1096:in perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:632:in
call_filter’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:438:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:638:in
call_filter’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:637:in
call_filter’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:438:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:638:in
call_filter’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:637:in
call_filter’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:449:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:619:in
perform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/benchmarking.rb:66:in
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in
measure’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/benchmarking.rb:66:in
perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/rescue.rb:83:in
perform_action’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:430:in send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:430:in
process_without_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:624:in
process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/session_management.rb:114:in
process’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:330:in process' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in
dispatch’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:
78:in process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb: 76:in
synchronize’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:
76:in process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in
process_client’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
process_client’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
initialize’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
run’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
new’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/ configurator.rb:271:in
run’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/
configurator.rb:270:in each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/ configurator.rb:270:in
run’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in
run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb: 211:in
run’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
/usr/bin/mongrel_rails:16:in `load’
/usr/bin/mongrel_rails:16