I have installed the latest version of rails and jruby. I have copied all my files from rails 2.3.5 version and am trying to bring all to work in this version Project.rb ------------------ class Project < ActiveRecord::Base has_and_belongs_to_many :people has_many :documents, :conditions => ["project_id =?", self.id ] .. .. end application_helper.rb -------------------------- def find_projects user = Person.find(session[:userid]) projects = Project.find(:all) .. .. .. end I am getting an error undefined method `id'' for #<Class:0x182237ac> (self.id is the problem guess) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
deal bitte wrote in post #1070764:> > Project.rb > ------------------ > class Project < ActiveRecord::Base > has_and_belongs_to_many :people > has_many :documents, :conditions => ["project_id =?", self.id ] > .. > .. > end > > application_helper.rb > -------------------------- > > def find_projects > user = Person.find(session[:userid]) > projects = Project.find(:all) > .. > .. > .. > end > > I am getting an error > undefined method `id'' for #<Class:0x182237ac> (self.id is the problem > guess)Not really answering your question here, but i would restructure some of this code as follows, to better go with rails 3 class Project < ActiveRecord::Base has_many :people, :through => ''people_project_join_table'' has_many :documents #:foreign_key => ''project_id'' is default for this relationship. Don''t need. .. .. def find_projects user = Person.find(session[:userid]) projects = Project.all .. .. .. end -- Beyond that, whenever you get an error like ''undefined method for class'', first make sure you''re in fact working with the class you think you''re working with by doing myobj.class a common slip-up for me is trying to use object methods on an array of said objects. Most scopes and associations will return arrays. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
I suggest opening your console - type Person - the console should return to_s of the class - if not, the person model isn''t in your path better yet, take this opportunity to write some tests - start with the Person model On 2012-07-31, at 2:38 PM, masta Blasta wrote:> deal bitte wrote in post #1070764: >> >> Project.rb >> ------------------ >> class Project < ActiveRecord::Base >> has_and_belongs_to_many :people >> has_many :documents, :conditions => ["project_id =?", self.id ] >> .. >> .. >> end >> >> application_helper.rb >> -------------------------- >> >> def find_projects >> user = Person.find(session[:userid]) >> projects = Project.find(:all) >> .. >> .. >> .. >> end >> >> I am getting an error >> undefined method `id'' for #<Class:0x182237ac> (self.id is the problem >> guess) > > Not really answering your question here, but i would restructure some of > this code as follows, to better go with rails 3 > > class Project < ActiveRecord::Base > has_many :people, :through => ''people_project_join_table'' > has_many :documents #:foreign_key => ''project_id'' is default for this > relationship. Don''t need. > .. > .. > > > def find_projects > user = Person.find(session[:userid]) > projects = Project.all > .. > .. > .. > end > -- > > Beyond that, whenever you get an error like ''undefined method for > class'', first make sure you''re in fact working with the class you think > you''re working with by doing myobj.class > > a common slip-up for me is trying to use object methods on an array of > said objects. Most scopes and associations will return arrays. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Tuesday, July 31, 2012 7:48:08 PM UTC+1, Jodi wrote:> > I suggest opening your console - type Person - the console should return > to_s of the class - if not, the person model isn''t in your path > > better yet, take this opportunity to write some tests+1> - start with the Person model > > On 2012-07-31, at 2:38 PM, masta Blasta wrote: > > > deal bitte wrote in post #1070764: > >> > >> Project.rb > >> ------------------ > >> class Project < ActiveRecord::Base > >> has_and_belongs_to_many :people > >> has_many :documents, :conditions => ["project_id =?", self.id ] >What does self.id refer to here? Has the project class been instantiated yet to make it available? Is it required?> >> .. > >> .. > >> end > >> > >> application_helper.rb > >> -------------------------- > >> > >> def find_projects > >> user = Person.find(session[:userid]) > >> projects = Project.find(:all) > >> .. > >> .. > >> .. > >> end > >> > >> I am getting an error > >> undefined method `id'' for #<Class:0x182237ac> (self.id is the problem > >> guess) > > > > Not really answering your question here, but i would restructure some of > > this code as follows, to better go with rails 3 > > > > class Project < ActiveRecord::Base > > has_many :people, :through => ''people_project_join_table'' > > has_many :documents #:foreign_key => ''project_id'' is default for this > > relationship. Don''t need. > > .. > > .. > > > > > > def find_projects > > user = Person.find(session[:userid]) > > projects = Project.all > > .. > > .. > > .. > > end > > -- > > > > Beyond that, whenever you get an error like ''undefined method for > > class'', first make sure you''re in fact working with the class you think > > you''re working with by doing myobj.class > > > > a common slip-up for me is trying to use object methods on an array of > > said objects. Most scopes and associations will return arrays. > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/f2lFuOijZ9AJ. For more options, visit https://groups.google.com/groups/opt_out.
Hello, Your class Project does not have a method by the name ''id''. Please review the logic of your code :-) On Tuesday, July 31, 2012 2:30:22 PM UTC+3, Ruby-Forum.com User wrote:> > I have installed the latest version of rails and jruby. I have copied > all my files from rails 2.3.5 version and am trying to bring all to work > in this version > > Project.rb > ------------------ > class Project < ActiveRecord::Base > has_and_belongs_to_many :people > has_many :documents, :conditions => ["project_id =?", self.id ] > .. > .. > end > > application_helper.rb > -------------------------- > > def find_projects > user = Person.find(session[:userid]) > projects = Project.find(:all) > .. > .. > .. > end > > I am getting an error > undefined method `id'' for #<Class:0x182237ac> (self.id is the problem > guess) > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Qo4e7fUbtEQJ. For more options, visit https://groups.google.com/groups/opt_out.