我是从here得到的,但我不知道放在哪里以及如何执行此操作。
我尝试创建类并通过控制台(rails c
)运行它,但它无效。
def setup_actions_controllers_db
write_permission("all", "manage", "Everything", "All operations", true)
controllers = Dir.new("#{Rails.root}/app/controllers").entries
controllers.each do |controller|
if controller =~ /_controller/
foo_bar = controller.camelize.gsub(".rb","").constantize.new
end
end
# You can change ApplicationController for a super-class used by your restricted controllers
ApplicationController.subclasses.each do |controller|
if controller.respond_to?(:permission)
clazz, description = controller.permission
write_permission(clazz, "manage", description, "All operations")
controller.action_methods.each do |action|
if action.to_s.index("_callback").nil?
action_desc, cancan_action = eval_cancan_action(action)
write_permission(clazz, cancan_action, description, action_desc)
end
end
end
end
end
and so on ...
请帮助我。谢谢
答案 0 :(得分:1)
您必须使用该代码创建rake
任务并在之后运行该任务,以便填充新创建的Permission
表。要创建rake任务,您需要在<newtask>.rake
。
lib/tasks/<newtask>.rake