将表单助手翻译为simple_form或formstatic

时间:2011-07-09 15:54:02

标签: ruby-on-rails ruby-on-rails-3 simple-form

我的模型中有这个:

class Person < ActiveRecord::Base
  RELATIONSHIP_STATUSES = [
    "single",
    "in a relationship",
    "together",
    "it's complicated"
  ]

  validates :relationship_status, :inclusion => RELATIONSHIP_STATUSES
end

在视图中:

collection_select(:person, :relationship_status, Person::RELATIONSHIP_STATUSES, :to_s)

我想将其转换为simple_form。这可能吗?

1 个答案:

答案 0 :(得分:0)

如果我理解你的话,这很简单(适用于formtastic):

<%= form.input :relationship_status, :as => :select, :collection => Person::RELATIONSHIP_STATUSES %>