Forum: Ruby on Rails Rails 2.1.2 => 2.2.2 Attempt to call private method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1bcec20cca6b6e9602403a90e74618ba?d=identicon&s=25 se_pavel (Guest)
on 2008-11-24 13:11
(Received via mailing list)
Hello All,

Controller code
---------
@dates = Q.find(:all,
:select => 'year(q.approved_at) as y, month(q.approved_at) as m, day
(q.approved_at) as d, count(*) as cnt',
other conditions

View code
---------
<% y = '' %>
<% for d in @dates
                if y.to_s != d.y.to_s

the new rails 2.2.2 says that

"Attempt to call private method

....attribute_methods.rb:236:in `method_missing'

How I should write my code, so I can select not only the Q table
fields, but also calculated fields ?

Regards,
Pavel
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2008-11-24 13:16
(Received via mailing list)
What is the full stack trace?
1bcec20cca6b6e9602403a90e74618ba?d=identicon&s=25 se_pavel (Guest)
on 2008-11-24 13:27
(Received via mailing list)
Is this enough ?

4: <% y = '' %>
5: <% for d in @dates
6:                if y.to_s != d.y.to_s


    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/
lib/active_record/attribute_methods.rb:236:in `method_missing'
    app/views/public/dates.rhtml:6
    app/views/public/dates.rhtml:5:in `each'
    app/views/public/dates.rhtml:5
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_view/renderable.rb:39:in `send'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_view/renderable.rb:39:in `render'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_view/template.rb:73:in `render_template'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_view/base.rb:256:in `render'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_view/base.rb:367:in `_render_with_layout'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_view/base.rb:254:in `render'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/base.rb:1174:in `render_for_file'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/base.rb:896:in `render_without_benchmark'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/benchmarking.rb:51:in `render'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/core_ext/benchmark.rb:8:in `realtime'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/benchmarking.rb:51:in `render'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/base.rb:868:in `render_without_benchmark'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/
action_controller/benchmarking.rb:51:in `render'
    c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/core_ext/benchmark.rb:8:in `real
1bcec20cca6b6e9602403a90e74618ba?d=identicon&s=25 se_pavel (Guest)
on 2008-11-24 13:56
(Received via mailing list)
> 4: <% y = '' %>
> 5: <% for d in @dates
> 6:                if y.to_s != d.y.to_s

also if I rewrite line 6 in the following way it works

6:                 if y != d['y'].to_s

but it requires to change a lot of code

Regards.
Pavel
7db10f6e5966cddb75eb2535d498ab18?d=identicon&s=25 dctabuyz (Guest)
on 2008-11-24 14:41
(Received via mailing list)
in fact the elements in @dates are not real membes of Q, they even
have nil value in id.
try to use @dates = ActiveRecord::Base.connection.select_values("
7db10f6e5966cddb75eb2535d498ab18?d=identicon&s=25 dctabuyz (Guest)
on 2008-11-24 15:14
(Received via mailing list)
ActiveRecord::Base.connection.select_all i meant
1bcec20cca6b6e9602403a90e74618ba?d=identicon&s=25 se_pavel (Guest)
on 2008-11-24 15:15
(Received via mailing list)
> in fact the elements in @dates are not real membes of Q, they even
> have nil value in id.
> try to use @dates = ActiveRecord::Base.connection.select_values("

this function doesn't support :first, :conditions, :joins and etc
params

Regards,
Pavel
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-25 09:54
(Received via mailing list)
On 24 Nov 2008, at 12:10, se_pavel wrote:

> View code
>
Don't call it y. There's already a method on object called y (seems to
do yaml dumps). You might be able to get round that with

class Q < ActiveRecord::Base
  undef_method :y
# rest of that class here
end

Fred
1bcec20cca6b6e9602403a90e74618ba?d=identicon&s=25 se_pavel (Guest)
on 2008-11-25 11:00
(Received via mailing list)
> Don't call it y. There's already a method on object called y (seems to  
> do yaml dumps). You might be able to get round that with
>
> class Q < ActiveRecord::Base
>   undef_method :y
> # rest of that class here
> end

yes, you are right .. I have renamed "y" to "year" and it works

Regards,
Pavel
This topic is locked and can not be replied to.