of all controllers and their methods.
use this script from rails console.
I have used this script to generate a migration file with default authorization roles & rights.
controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries controllers.each do |controller| if controller =~ /_controller/ cont = controller.camelize.gsub(".rb","") puts cont (eval("#{cont}.new.methods") - ApplicationController.methods - Object.methods - ApplicationController.new.methods).sort.each {|met| puts "\t#{met}" } end end
to use it to create a Right object I used the following adjustments:
controllers.each do |controller| if controller =~ /_controller/ name = controller.camelize.gsub(".rb","") (eval("#{name}.new.methods") - Object.methods - ApplicationController.new.methods).sort.each {|met| name_short = name.gsub("Controller","").downcase #it is possible to call the create directly from this script #I wanted to review and revise the names. puts "#{met}_#{name_short}=Right.create(:name=>\"#{met} #{name_short}\", :controller=>\"#{name_short}\", :action=>\"#{met}\")"} end end
controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries