Tutorials "How to develop plugins?"

good place to start for the basics

http://wiki.rubyonrails.com/rails/pages/HowTosPlugins

perhaps a rake task would be what you want then?

Then Rails::Generator::NamedBase has a method to do this. I found it while making a generator to generate generators. I have yet to use this fun resource but here is the code.

m.route_resources(*resources)

#from the command.rb def route_resources(*resources) resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') sentinel = ‘ActionController::Routing::Routes.draw do |map|’

logger.route “map.resources #{resource_list}” unless options[:pretend] gsub_file ‘config/routes.rb’, /(#{Regexp.escape(sentinel)})/mi do |match| “#{match}\n map.resources #{resource_list}\n” end end end

Hope this is useful.

Stephen Becker IV

I believe it creates the route.rb file with the resources that are passed in, and tries to add it to the current routes. This is a method from the generator base class. When you create a generator its one of the methods you have access to. I did not notice before the gsub_file is another method. I am using a frozen version of rails, but the file I found these in are in the vender/railites/lib/rails_generator/command.rb I was under the impression that you wanted to update the routes file and I believe that this is what this code does.

As for using it. I have not. The only place I have seen this used is here http://canofcode.com/rails/repository/6069/trunk/railties/lib/rails_generator/generators/components/resource/resource_generator.rb

Looks like they just pass the name of the resource to it. You might have to tweak the out put to the routes file.

def gsub_file(relative_destination, regexp, *args, &block) path = destination_path(relative_destination) content = File.read(path).gsub(regexp, *args, &block) File.open (path, ‘wb’) { |file| file.write(content) } end

Stephen Becker IV

You can you reuse your code in RoR applications. Looking at the http://www.ruby-forum.com/topic/102607 post you can make a plugin (which I have not) or a generator. For a generator you can make template of files and then run ruby script/generate that_thing_you_made with_some options_too

How complicated are your files? Do they need to dynamic? SVN externals could work too.