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 :P thanxs allot ! gr heldopslippers -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Le 25 Mar 2008 à 22:08, Heldop Slippers a écrit :> > 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 > >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> > the model: > > class Animal > def item > return 2 > end > end > > > I hope someone can see the (probably stupid) fault here :P > > thanxs allot ! > gr heldopslippers > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> Le 25 Mar 2008 � 22:08, Heldop Slippers 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 ...) > > Fredthanxs for the reply ! :D and well what i want is to have al my database methods in the model (of course ;) ). 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 ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Heldop Slippers 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:ClassAs 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---