leonb
January 18, 2008, 10:56am
1
Hi,
At what point in rails are the methods for a models attributes defined?
Because I have the following code:
Parked at Loopia
And it returns in irb:
s = Playlist.find(:first).songs
false
1
If I do this in irb: (The PlaylistItem model has an attribute ‘position’
s = Playlist.find(:first).playlist_items[0].methods(true).include?(‘position’)
true
How’s that possible? Does irb do some fancy trick to retrieve all
methods?
Must I do something in the instance_eval to make the methods appear?
leonb
January 18, 2008, 11:21am
2
On 18 Jan 2008, at 09:56, Leon B. wrote:
Hi,
At what point in rails are the methods for a models attributes
defined?
Because I have the following code:
Parked at Loopia
How’s that possible? Does irb do some fancy trick to retrieve all
methods?
Must I do something in the instance_eval to make the methods appear?
They get generated when they are needed (via method_missing). Why do
you care about whether the methods exists rather than just going ahead
and calling them ?
Fred
leonb
January 18, 2008, 11:30am
3
Because the actual script is something like:
association_through_item.methods(true).each do |method|
#No method position here!
association_through_item.send(association_method).meta_eval do
define_method method do
association_through_item.send(method)
end
end
end
So position never gets called because it’s not in methods()
leonb
January 18, 2008, 1:46pm
4
Thanks Fred! Worked like a charm.
leonb
January 18, 2008, 12:03pm
5
On 18 Jan 2008, at 10:30, Leon B. wrote:
end
end
end
So position never gets called because it’s not in methods()
You could try calling PlayListItem.define_attribute_methods
Fred