0

我有一个名为优先级的代码表。该表有一个名为存档的布尔值。我有一个请求表,它的表格包含优先级选择列表。我正在使用范围声明来判断优先级是否已归档。这是模型中的代码:

scope :archived, where(:archive => true)
scope :active, where(:archive => false)

我正在尝试使用请求表单中的范围,如下所示:

        <%= f.association :priority, :label_method => :prioritycode.active, :label => 'Priority' %>

但是,这是行不通的。

我应该在表格中使用什么?

谢谢!

4

2 回答 2

0

我可能遗漏了一些东西——不熟悉association您正在使用的助手。

如果你想要一个下拉选择列表,我会做类似的事情

<%= f.collection_select :priority, Priority.active, :id, :name %>

(假设您有一个定义Priority了范围的模型:active,并且优先级具有name. 您的里程可能会有所不同。)

于 2012-11-28T17:52:10.310 回答
0

tharrison 帖子让我思考(谢谢) - 这很有效:

        <%= f.association :priority, :collection => Priority.active.all, :label_method => :prioritycode, :label => 'Priority' %>
于 2012-11-28T18:16:04.870 回答