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.
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 %>
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 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 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 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 %> ?