Created
February 22, 2012 04:27
-
-
Save sudodo/1881365 to your computer and use it in GitHub Desktop.
Rake task to print a table for show.html.erb' in a Rails app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #encoding: utf-8 | |
| require 'rake' | |
| task :show_table_gen, :arg1 do |t, arg| | |
| # TODO eval(arg[]) is NOT secure code. | |
| model_name = eval(arg['arg1']) # => NOT secure code... | |
| str = <<-EOS | |
| <table> | |
| EOS | |
| model_name.column_names.each do |column| | |
| str += <<-EOS | |
| <th> | |
| column | |
| </th> | |
| EOS | |
| end | |
| puts str | |
| end | |
| namespace :show_erb_gen do | |
| desc 'generate show page. usage: rake show_erb_gen:run MODEL=TblSystem' | |
| task :run => :environment do | |
| puts "Model is #{ENV['MODEL']}" | |
| Rake::Task[:show_table_gen].invoke(ENV['MODEL']) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment