Model problem

because I am using Filemaker pro 9 and the Rfm extension I cannot use
ActiveRecord. But of course I would like to use the models to have my
database connection, selection things in.

But I can’t manage to let this work.
This is one of the many things I tried:

the controller:

class AnimalsController < ApplicationController
def index
@id= Animal.item
end
end

the model:

class Animal
def item
return 2
end
end

I hope someone can see the (probably stupid) fault here :stuck_out_tongue:

thanxs allot !
gr heldopslippers

Frederick C. wrote:

Le 25 Mar 2008 � 22:08, Heldop S. a �crit :

class AnimalsController < ApplicationController
def index
@id= Animal.item
end
end

You’ve created an instance method called item in your model, but
you’re using it as a class method. I can’t guess what you’re trying to
do, but either you change your controller so that it’s working with an
instance of Animal, or make the item method a class method (def
self.item …)

Fred

thanxs for the reply ! :smiley:
and well what i want is to have al my database methods in the model (of
course :wink: ).
But beceause I use Rfm I can not use ActiveRecord.

this is a sample code that should (I think work). but doens’t …

the controller:

class AnimalsController < ApplicationController
def index
@id = Animals.item
end
end

model:

class Animals
def item
return 2
end
end

The Animals should be a class and the item should be a method.
but when I try to run this it gives: undefined method `item’ for
Animals:Class

why ?

Le 25 Mar 2008 à 22:08, Heldop S. a écrit :

class AnimalsController < ApplicationController
def index
@id= Animal.item
end
end

You’ve created an instance method called item in your model, but
you’re using it as a class method. I can’t guess what you’re trying to
do, but either you change your controller so that it’s working with an
instance of Animal, or make the item method a class method (def
self.item …)

Fred

Heldop S. wrote:

 @id = Animals.item

class Animals
def item

The Animals should be a class and the item should be a method.
but when I try to run this it gives: undefined method `item’ for
Animals:Class

As Fred pointed out, you have defined an instance method, but you are
using it like a class method.

Class methods are methods invoked on a class and defined like this (not
the reference to “self” which here stands for the class itself):

class Animals
def self.item
return 2
end
end

These methods are independent of any particular Animal (known as
instances). They are designed to allow you to provide functionality
about the class itself, such as creating new instances, etc. You call
them like this:

Animals.item

Instance methods are methods invoked on a particular item of a class (an
instance of that class). These allow you to manipulate or investigate
specific instances of your class and are defined like this:

class Animals
def item
return 2
end
end

You call this on a particular Animal. You might get this from another
method, or create a new one yourself:

my_animal = Animals.new

Then you can call this instance method:

my_animal.item

These concept of class and instance and the distinction between the
methods for each are at the core of Object Oriented Programming.

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