Calling a method in console

I’m using the Ruby for Rails book and have all the code done and
application works.
However I’d like to access some of the methods through script/console.

For example in the edition model file (below) I’d like to know how to
call either the “Edition_of_Works” or composers methods:

class Edition < ActiveRecord::Base
has_and_belongs_to_many :works
has_many :orders
belongs_to :publisher

def Edition.of_works(works)
works.map {|work| work.editions }.flatten.uniq
end

def composers
works.map {|work| work.composer }.uniq
end…
end

TIA
Stuart

On Aug 14, 2006, at 8:52 AM, Dark A. wrote:

has_many :orders
end

TIA
Stuart

Hey Stuart-

Here is how to call those methods:

$ script/console

Edition.of_works(whatever)

and for the composers you need an instance

ed = Edition.find :first # or an id here
ed.composers

Thats it

-EZra

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs