我有基於數據庫結構構建GUI的帶有activescaffold的ruby-on-rails應用程序。 用戶有角色,每個角色是一組權限。每個權限都是控制器和用戶被允許在該控制器中執行的操作的組合。ruby-on-rails中的幫助列覆蓋
# DATABASE!
create_table :rights do |t|
t.column :controller, :string, :limit => 32, :null => false
t.column :action, :string, :limit => 32, :null => false
end
create_table :rights_roles, :id => false do |t|
t.column :right_id, :integer
t.column :role_id, :integer
end
create_table :roles do |t|
t.column :name, :string, :limit => 32, :null => false
end
#MODELS!
class Role < ActiveRecord::Base
has_and_belongs_to_many :rights
class Right < ActiveRecord::Base
has_and_belongs_to_many :roles
# ROLE CONTROLLER!
class RoleController < ApplicationController
active_scaffold :role do |config|
config.columns = Array[:name, :rights]
config.columns[:rights].form_ui = :select
我現在有以下的角色編輯窗口,它是不方便(選項不規整將會有更多的動作,因此這將是可怕的。):
http://postimage.org/image/4e8ukk2px/
我想創建一個這樣的幫手方法:
module RoleHelper
def rights_form_column (record, input_name)
...
end
end
這是需要定義的表單,它將指定「權限」列的輸入方法。但我不知道該怎麼寫。 期望的形式將以下內容:
administration
action1(checkbox)
action2(checkbox)
configuration
action1(checkbox)
...
我知道activescaffold是老了,但我不得不使用它...請幫助!