English 中文(简体)
我的反对关系中是否有任何错误?
原标题:Is there any wrong in my object relationship?

我希望这些命令具有不同的秩序状态,因此我有一个称为“地位”的表格。 页: 1

class Status < ActiveRecord::Base
  belongs_to :order 
  attr_accessible :name

end

这是我的命令。 rb:

class Order < ActiveRecord::Base
  :es
end

我认为,我试图将相关地位称为:

    <%= order.statuses.name%>

因此,我这样说:

<% order.statuses.each_with_index do |order_status, index| %>
<%= order_status.name%>
<% end %>

它仍然没有工作。 我有这样的错误:

尚未颁布的持续命令:

我将我的守则改为:

应当:

:

以及

页: 1

但我有这个错误:

页: 1

我只想到有关地位的命令,但地位与命令无关,我是否能够这样做?

最佳回答

由于复数制,你再次出现错误。 应:

class Order < ActiveRecord::Base
  has_one :status
end

However,它像你可能拥有的属性一样,具有一种后向关系。 如果你只想在数据库中拥有少数地位(例如:待决、账单、装运、完整),则地位应<代码>has_many 令,每项命令应belongs_toa Status。 你们现在建立起来的方式是,每项命令都将有一个单独的地位问题标。 这可能是你想要的,但确保你明白,这意味着每个地位都不同(也许每个是判决,或两个描述命令)。

问题回答

应当:

:

以及

页: 1

铁路局的R.R.R.R.R.建构。

由于你将关系定义为<代码>has_one。 页: 1





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签