get_location is an instance method of Note but you’re trying to call
it on a collection of notes (Because associations are also scopes you
can call class methods on them: this just calls the class method with
finds etc scoped appropriately, but I’m not sure if that is what you
were trying to do).
On Sat, Jul 10, 2010 at 1:48 PM, Szymon Przybył [email protected]
wrote:
But even if I call “Note.get_location(1)”, it throws the same error
As Frederick says, this is an instance method, you’re trying to call
it on the class.
You should do something like @pattern.notes.first.get_location
I highly recommend you to take a look at the rails guides.
But I want use it in views, pattern.notes.get_location(location) looks
much better, but how can I make it works?
I am not sure what you are trying to do. Are you trying to find all
the notes for that pattern where the location is a specified value?
If so you could use Note.find with a condition that note.pattern is
the one you want and location is the location you want. In fact I
think you should be able to use something like
Note.find_all_by_pattern_id_and_location( pattern.id, location )
Alternatively pattern.notes.select{ |n| n.location ==
required_location } or something similar. If you like this I would
make it a method of Pattern so that you can say something like
pattern.notes_for_location( required_location )
As an earlier poster suggested, have a look at the rails guides,
By the way it is preferred here to insert replies into the previous
post at the appropriate point rather than top posting. It makes it
easier to follow the thread. Thanks
Wow, I didn’t know that there are find_by_property methods already
defined, ruby and rails are just great! I’m switching now from
Kohana in PHP to Ruby on Rails, and I can say now, that ruby and rails
are much better Thanks again!
Simon
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.