I want which order have different order status, so I have a table called "status", in the status.rb, it likes this:
class Status < ActiveRecord::Base
belongs_to :order
attr_accessible :name
end
And this is my order.rb:
class Order < ActiveRecord::Base
has_one :statuses
end
In my view, I try to call the related status like this:
<%= order.statuses.name%>
It don't work, so , I called it in this way:
<% order.statuses.each_with_index do |order_status, index| %>
<%= order_status.name%>
<% end %>
It still don't work. I have the error like this:
uninitialized constant Order::Statuses
I changed my code to this:
It should be
has_one :status
and
order.status.name
But I have this error:
SQLite3::SQLException: no such column: statuses.order_id: SELECT * FROM "statuses" WHERE ("statuses".order_id = 5) LIMIT 1
I only want the order related to the status, but the status is not related to the order, can I do so?