Naming conventions for models in ruby on rails are overridden.Entity User and Responder have many to many association between them.It is expressed with has many through. Following are the model files: user.rb: has_many :Usertoresponder has_many :responder, :through => :Usertoresponder responder.rb: has_many :Usertoresponder has_many :user, :through => :Usertoresponder , :dependent => :destroy usertoresponder.rb: class Usertoresponder < ActiveRecord::Base self.table_name = ''User_To_Responder'' belongs_to :user belongs_to :responder end But when saving or getting responder through user there is a problem occurring it says - user.responder is not defined. And the above problem is not occurring when its done using test case but its occurring if its done through http request. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2011-Mar-14 08:00 UTC
Re: Problem when naming conventions in ruby are overriden
On 14 March 2011 05:44, Renuka <renuka.patil17-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Naming conventions for models in ruby on rails are overridden.Entity > User and Responder have many to many association between them.It is > expressed with has many through.You''re not overriding naming conventions - you''re getting cases and syntax wrong... Corrected off the top of my head: user.rb: has_many :usertoresponder has_many :responder, :through => :usertoresponder responder.rb: has_many :usertoresponder has_many :user, :through => :usertoresponder , :dependent => :destroy usertoresponder.rb: class Usertoresponder < ActiveRecord::Base self.table_name = ''User_To_Responder'' belongs_to :user belongs_to :responder end BTW What reason is there for not calling the class "UserToResponder"? -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Renuka Patil
2011-Mar-14 08:57 UTC
Re: Problem when naming conventions in ruby are overriden
Yes class name can be UserToResponder , there is no reason to keep the class name usertoresponder. Where are the syntax errors? Same thing is working with test case On Mon, Mar 14, 2011 at 1:30 PM, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 14 March 2011 05:44, Renuka <renuka.patil17-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Naming conventions for models in ruby on rails are overridden.Entity > > User and Responder have many to many association between them.It is > > expressed with has many through. > > You''re not overriding naming conventions - you''re getting cases and > syntax wrong... > > Corrected off the top of my head: > > user.rb: > has_many :usertoresponder > has_many :responder, :through => :usertoresponder > > responder.rb: > has_many :usertoresponder > has_many :user, :through => :usertoresponder , :dependent => :destroy > > usertoresponder.rb: > class Usertoresponder < ActiveRecord::Base > self.table_name = ''User_To_Responder'' > belongs_to :user > belongs_to :responder > end > > > BTW What reason is there for not calling the class "UserToResponder"? > > -- > 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 this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.