Rails 2.1.2 => 2.2.2 Attempt to call private method


#1

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


#2

What is the full stack trace?


#3

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:ineach’
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:inrender’
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:inrender’
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:inrender’
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:inrender_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:inrealtime’
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:inrender_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:inreal


#4

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


#5

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("


#6

ActiveRecord::Base.connection.select_all i meant


#7

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


#8

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


#9

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