Friday, June 6, 2008

List all Controllers and actions

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

Dump a Model table to fixtures

 


def self.to_fixture
write_file(File.expand_path("test/fixtures/#{table_name}.yml", RAILS_ROOT),
self.find(:all).inject("---\n") { |s, record|
self.columns.inject(s+"#{record.id}:\n") { |s, c|
s+" #{{c.name => record.attributes[c.name]}.to_yaml[5..-1]}\n" }
})
end