ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-25 21:06 UTC
NameError, uninitialized constant States
I''m completely new to Ruby and Rails and could use some help resolving an issue. I have a list method that is supposed to show the titles and states(status) of requests, but I get an error from this piece of code: <td><%= change.states.state %></td> The error is: c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant States The states table contains an id and state field. The changes table holds a foreign key named state_id that references the states table. I want this code to simply display the text from the state field for the specified change request. Can anyone tell me what''s wrong? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-25 21:06 UTC
NameError, uninitialized constant States
I''m completely new to Ruby and Rails and could use some help resolving an issue. I have a list method that is supposed to show the titles and states(status) of requests, but I get an error from this piece of code: <td><%= change.states.state %></td> The error is: c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant States The states table contains an id and state field. The changes table holds a foreign key named state_id that references the states table. I want this code to simply display the text from the state field for the specified change request. Can anyone tell me what''s wrong? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-25 21:06 UTC
NameError, uninitialized constant States
I''m completely new to Ruby and Rails and could use some help resolving an issue. I have a list method that is supposed to show the titles and states(status) of requests, but I get an error from this piece of code: <td><%= change.states.state %></td> The error is: c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant States The states table contains an id and state field. The changes table holds a foreign key named state_id that references the states table. I want this code to simply display the text from the state field for the specified change request. Can anyone tell me what''s wrong? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In your Change model, do you have belongs_to :state ? From what I can tell, this is what you should have if your changes table has a fk field called state_id which links over to the states table''s id field. If these assumptions are correct, you would want to do <%change.state.state %> On 10/25/06, ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m completely new to Ruby and Rails and could use some help resolving > an issue. I have a list method that is supposed to show the titles and > states(status) of requests, but I get an error from this piece of code: > > <td><%= change.states.state %></td> > > The error is: > > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in > `const_missing'': uninitialized constant States > > The states table contains an id and state field. The changes table > holds a foreign key named state_id that references the states table. > > I want this code to simply display the text from the state field for > the specified change request. > > Can anyone tell me what''s wrong? > > > > >-- Thomas Mango tsmango-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26 13:38 UTC
Re: NameError, uninitialized constant States
I do have an entry in my Change model, but it says belongs_to:states. I also have an entry in the state model saying has_many:changes. When I try to use <%= change.state.state %> I get a no method found error, which is why I was trying <%= change.states.state %>. I have other tables with similar foreign key relationships and they all seem to work fine. On Oct 25, 4:11 pm, "Thomas Mango" <tsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In your Change model, do you have belongs_to :state ? From what I can > tell, this is what you should have if your changes table has a fk > field called state_id which links over to the states table''s id field. > If these assumptions are correct, you would want to do <%> change.state.state %> > > On 10/25/06, rya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <rya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''m completely new to Ruby and Rails and could use some help resolving > > an issue. I have a list method that is supposed to show the titles and > > states(status) of requests, but I get an error from this piece of code: > > > <td><%= change.states.state %></td> > > > The error is: > > > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in > > `const_missing'': uninitialized constant States > > > The states table contains an id and state field. The changes table > > holds a foreign key named state_id that references the states table. > > > I want this code to simply display the text from the state field for > > the specified change request. > > > Can anyone tell me what''s wrong?-- > Thomas Mango > tsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26 13:38 UTC
Re: NameError, uninitialized constant States
I do have an entry in my Change model, but it says belongs_to:states. I also have an entry in the state model saying has_many:changes. When I try to use <%= change.state.state %> I get a no method found error, which is why I was trying <%= change.states.state %>. I have other tables with similar foreign key relationships and they all seem to work fine. On Oct 25, 4:11 pm, "Thomas Mango" <tsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In your Change model, do you have belongs_to :state ? From what I can > tell, this is what you should have if your changes table has a fk > field called state_id which links over to the states table''s id field. > If these assumptions are correct, you would want to do <%> change.state.state %> > > On 10/25/06, rya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <rya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''m completely new to Ruby and Rails and could use some help resolving > > an issue. I have a list method that is supposed to show the titles and > > states(status) of requests, but I get an error from this piece of code: > > > <td><%= change.states.state %></td> > > > The error is: > > > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in > > `const_missing'': uninitialized constant States > > > The states table contains an id and state field. The changes table > > holds a foreign key named state_id that references the states table. > > > I want this code to simply display the text from the state field for > > the specified change request. > > > Can anyone tell me what''s wrong?-- > Thomas Mango > tsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26 13:38 UTC
Re: NameError, uninitialized constant States
I do have an entry in my Change model, but it says belongs_to:states. I also have an entry in the state model saying has_many:changes. When I try to use <%= change.state.state %> I get a no method found error, which is why I was trying <%= change.states.state %>. I have other tables with similar foreign key relationships and they all seem to work fine. On Oct 25, 4:11 pm, "Thomas Mango" <tsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In your Change model, do you have belongs_to :state ? From what I can > tell, this is what you should have if your changes table has a fk > field called state_id which links over to the states table''s id field. > If these assumptions are correct, you would want to do <%> change.state.state %> > > On 10/25/06, rya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <rya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''m completely new to Ruby and Rails and could use some help resolving > > an issue. I have a list method that is supposed to show the titles and > > states(status) of requests, but I get an error from this piece of code: > > > <td><%= change.states.state %></td> > > > The error is: > > > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in > > `const_missing'': uninitialized constant States > > > The states table contains an id and state field. The changes table > > holds a foreign key named state_id that references the states table. > > > I want this code to simply display the text from the state field for > > the specified change request. > > > Can anyone tell me what''s wrong?-- > Thomas Mango > tsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
1) why do you post all your replies 3 times? :) 2) it has to be: belongs_to :state belongs_to are always singluar, has_many are always plural. like you would read it out loud: a change belongs to a state, and a state has many changes --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello Ryan,> I do have an entry in my Change model, but it says belongs_to:states. > I also have an entry in the state model saying has_many:changes. > When I try to use <%= change.state.state %> I get a no method found > error, which is why I was trying <%= change.states.state %>.Have you tried with belongs_to :state (singular) and <%= change.state.state %> ? -- Jean-François. -- À la renverse. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> I do have an entry in my Change model, but it says belongs_to:states. > I also have an entry in the state model saying has_many:changes. When > I try to use <%= change.state.state %> I get a no method found error, > which is why I was trying <%= change.states.state %>. I have other > tables with similar foreign key relationships and they all seem to work > fine.I think that when you call change.states, "belongs_to :states" in your Change model tries to find a States model and fails when it doesn''t exist. You should have "has_many :changes" in your State model (so it sounds like you have that part right), and "belongs_to :state" in your Change model (a State can have many Changes, but a Change belongs only to a single State). This will give you change.state.state in your controllers/views. The only other suggestion I would make would be to possibly change the name of your data column to "name" - state.state is kind of redundant, whereas state.name seems a little clearer. Comes down to personal preference and what makes sense to you, though. -- 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26 14:32 UTC
Re: NameError, uninitialized constant States
1) I think there''s a problem with my proxy server at work from where I''m posting. 2) The singular version worked. I guess I didn''t pay enough attention to the method parts. Ryan On Oct 26, 6:56 am, "Thorsten L" <duple...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 1) why do you post all your replies 3 times? :) > > 2) it has to be: belongs_to :state > > belongs_to are always singluar, has_many are always plural. > > like you would read it out loud: a change belongs to a state, and a > state has many changes--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26 14:39 UTC
Re: NameError, uninitialized constant States
Merci Jean-François, Ca a marché! On Oct 26, 7:11 am, "Jean-François" <jf.w...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Ryan, > > > I do have an entry in my Change model, but it says belongs_to:states. > > I also have an entry in the state model saying has_many:changes. > > When I try to use <%= change.state.state %> I get a no method found > > error, which is why I was trying <%= change.states.state %>.Have you tried with belongs_to :state > (singular) and <%= change.state.state %> ? > > -- Jean-François. > > -- > À la renverse.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryansv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-26 14:47 UTC
Re: NameError, uninitialized constant States
Merci Jean-François, Ca a marché! On Oct 26, 7:11 am, "Jean-François" <jf.w...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Ryan, > > > I do have an entry in my Change model, but it says belongs_to:states. > > I also have an entry in the state model saying has_many:changes. > > When I try to use <%= change.state.state %> I get a no method found > > error, which is why I was trying <%= change.states.state %>.Have you tried with belongs_to :state > (singular) and <%= change.state.state %> ? > > -- Jean-François. > > -- > À la renverse.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---