Monday, November 30, 2009

Pass and catch parameters with RAKE command in Rails Application

1. Create a rake file(suppose pass_catch_rake_params.rake) into your project's lib/tasks folder

2. Edit this rake file with the following code:
 task :rake_task => :environment do
    puts ENV['param1'] # You are catching param1
    puts ENV['param2'] # You are catching param2

3. Run the Rake command like this:
  rake rake_task param1=10 param2='This is a string'

Where rake_task is the rake task name and param1,param2 are the parameters name
In your rake task you will get param1 and param2 with their assigned value

No comments:

Post a Comment