hi,
I am trying to collect all controllers names in application.
how to get directory contents under /app/controllers/
any1 have any idea
I look up the File & FileUtils classes, but cant find anything
thanks
serz
hi,
I am trying to collect all controllers names in application.
how to get directory contents under /app/controllers/
any1 have any idea
I look up the File & FileUtils classes, but cant find anything
thanks
serz
def find_controller_names
a = []
Find.find( RAILS_ROOT + ‘/app/controllers’ ) do |file_name|
if /.rb$/ =~ file_name
a << File.basename(file_name).gsub(’.rb’, ‘’).camelcase
end
end
render_text a.inspect
end
if you run find_controller_names, you’ll get something like
[“Application”, “SomeController”, “OtherController”]
hope it helps!
Shai R. wrote:
def find_controller_names
a = []
Find.find( RAILS_ROOT + ‘/app/controllers’ ) do |file_name|
if /.rb$/ =~ file_name
a << File.basename(file_name).gsub(’.rb’, ‘’).camelcase
end
end
render_text a.inspect
endif you run find_controller_names, you’ll get something like
[“Application”, “SomeController”, “OtherController”]hope it helps!
hi shai, thanks it is exactly what i want
meanwhile i find Dir.entries("#{RAILS_ROOT}/app/controllers/")
but i get controllers filenames, like admin_controller.rb
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs