Многоуровневая сложная форма с формастастом? - PullRequest
0 голосов
/ 10 декабря 2010

У меня есть сценарий, который нуждается в очень сложной форме, и мне нужна помощь в этом.

У меня есть три таблицы

create_table "permissions", :force => true do |t|
    t.boolean  "can_read"
    t.boolean  "can_create"
    t.boolean  "can_edit"
    t.boolean  "can_delete"
    t.integer  "role_id"
    t.integer  "resource_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

create_table "resources", :force => true do |t|
    t.string   "class_name"
    t.string   "class_action"
    t.text     "description"
    t.integer  "parent_resource"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

create_table "roles", :force => true do |t|
    t.string   "name"
    t.text     "description"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

с моделями и ассоциациями

class Role < ActiveRecord::Base
  has_many :user_roles
  has_many :users, :through => :user_roles
  has_many :permissions

  def to_s
    self.name
  end
end

class Resource < ActiveRecord::Base
  has_many :permissions
  has_many :children, :class_name => "Resource", :foreign_key => "parent_resource"

  scope :root, lambda {
    {
      :conditions => "parent_resource IS NULL"
    }
  }
end

class Permission < ActiveRecord::Base
  belongs_to :role
  belongs_to :resource
end

Предположим, у нас есть две роли: администратор, пользователь, на этот раз мне нужна структура формы, подобная изображению в этой ссылке

Как я могу создать эту форму?Заранее спасибо.

1 Ответ

0 голосов
/ 10 декабря 2010

Я создал драгоценный камень, который облегчает обработку вложенных форм внутри formtastic: formtastic_cocoon .

Это должно помочь вам начать.

...