0

非常に複雑なフォームを必要とするシナリオがあり、それについて助けが必要です。

私は3つのテーブルを持っています

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

管理者とユーザーの 2 つのロールがあるとします。今回は、このリンクの画像のようなフォーム構造が必要です。

どうすればこのフォームを作成できますか? 前もって感謝します。

4

1 に答える 1

0

formtastic内のネストされたフォームの処理を容易にするgemを作成しました:formtastic_cocoon

それはあなたが始めるはずです。

于 2010-12-10T12:57:35.447 に答える