Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2010 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/575243 to your computer and use it in GitHub Desktop.
Save anonymous/575243 to your computer and use it in GitHub Desktop.
<textarea name="styled-results" id="rake"><%= @lines %></textarea>
def call_rake(task, os, options = {})
options[:rails_env] ||= Rails.env
args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" }
system "/usr/bin/rake #{task} #{args.join(' ')} --trace" if os == 'linux'
system "START /B rake.bat #{task} #{args.join(' ')} --trace" if os == 'windows'
end
textarea#rake {
width: 550px;
height: 200px;
border: 3px solid #cccccc;
padding: 5px;
font-family: Tahoma, sans-serif;
}
desc "Example Task to run manually"
task :example_task => :environment do
#************************************************************************************************
# Perform an example task
#************************************************************************************************
model_example = MyModel.find(:all)
File.open(RAKE_FILE_LOGS, "w") { |f|
f.puts "Rake File: My Example Task| #{Time.now}"
f.puts "_________________________________________________________________________"
model_example.each do |line|
f.puts "Row example data #{line.name}"
end
}
end
<div id="content" style="width:905px;">
<div id="conttwothirds">
<h3 style="clear:left;">Rake Tasks (In <%= Rails.env.to_s.capitalize %> Mode)</h3>
<p class="padding-left"><strong><%= link_to_remote( "Read Rake Results", :url =>{ :controller => "raketasks", :action => :call_render }) %></strong></p>
<div id="rake"></div>
</div>
<div id="contonethird">
<h5 class="side" style="margin-top:20px;">My Rake Tasks</h5>
<ul>
<li><%= link_to "Example Rake Task", rake_example_task %></li>
</ul>
<h5 class="side" style="margin-top:20px;">Other Rake Tasks</h5>
<ul>
<li>Etc..</li>
<li>Etc..</li>
<li>Etc..</li>
</ul>
</div>
</div>
class RaketasksController < ApplicationController
before_filter :login_required, :authorize
before_filter :set_pagetitle
def set_pagetitle
@pagetitle = "Raketasks"
end
def index
end
def rake_example_task
Rails.env == 'development' ? (call_rake :example_task, 'windows') : (call_rake :example_task, 'linux')
flash[:notice] = "Example task is running."
redirect_to raketasks_url
end
def call_render
@lines = ""
rakeread = IO.readlines(RAKE_FILE_LOGS)
rakeread.each do |line|
@lines << line
end
render :update do |page|
page.replace_html "rake", :partial => "rake_partial"
end
end
end
map.resources :raketasks, :only => :index
map.rake_example_task '/rake_example_task', :controller => 'raketasks', :action => 'rake_example_task'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment