开发者

Multilevel Complex form with formtastic?

I have a scenario which needs a very complex form, and i need help in it.

I have three tables

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

with the models and associations

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 P开发者_开发知识库ermission < ActiveRecord::Base
  belongs_to :role
  belongs_to :resource
end

Suppose we have 2 roles, admin, user, this time, i need a form structure like the image in the this link

How can i make this form? Thanks in advance.


I created a gem that makes it easier to handle nested forms inside formtastic: formtastic_cocoon.

That should get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜