Skip to content

Instantly share code, notes, and snippets.

@sudodo
Created February 22, 2012 04:27
Show Gist options
  • Select an option

  • Save sudodo/1881365 to your computer and use it in GitHub Desktop.

Select an option

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.
#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