Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Created March 22, 2012 14:54
Show Gist options
  • Save jcasimir/2158793 to your computer and use it in GitHub Desktop.
Save jcasimir/2158793 to your computer and use it in GitHub Desktop.
Rake Instead of Rails
jsblogger_advanced$ rake generate model Moderator username:string
invoke active_record
create db/migrate/20120322145332_create_moderators.rb
create app/models/moderator.rb
invoke rspec
create spec/models/moderator_spec.rb
jsblogger_advanced$ rake destroy model Moderator
invoke active_record
remove db/migrate/20120322145332_create_moderators.rb
remove app/models/moderator.rb
invoke rspec
remove spec/models/moderator_spec.rb
jsblogger_advanced$ rake server
=> Booting WEBrick
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-03-22 10:53:51] INFO WEBrick 1.3.1
[2012-03-22 10:53:51] INFO ruby 1.9.2 (2012-02-14) [x86_64-darwin11.3.0]
[2012-03-22 10:53:51] INFO WEBrick::HTTPServer#start: pid=14209 port=3000
^C[2012-03-22 10:53:53] INFO going to shutdown ...
[2012-03-22 10:53:53] INFO WEBrick::HTTPServer#start done.
Exiting
jsblogger_advanced$ rake console
Loading development environment (Rails 3.2.1)
1.9.2-p318 :001 > exit
jsblogger_advanced$
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
JsbloggerCodemash::Application.load_tasks
[:generate, :destroy, :server, :console].each do |command|
desc "Proof-of-concept proxy to the rails CLI"
task command do
system("rails #{command} #{ARGV[1..-1].join(' ')}")
exit
end
end
@jschairb
Copy link

+1 the usage of rake for some things but rails for others is inconsistent and could be tightened up

@davetron5000
Copy link

I have been very disappointed that rake server didn't work, so I like this

@TrevorBramble
Copy link

A thousand times, yes.

@amateurhuman
Copy link

Does this confuse the distinction between Rake as an independent tool from Rails as an independent tool? More specifically, do newcomers skip over the power of using Rake exclusively with Ruby and just associate it as a Rails tool?

I'd love to hear the motivation behind the idea. What pains are you trying to alleviate with it?

@marktabler
Copy link

It does feel arbitrary that I start a server with rails server but I migrate the database my server depends on with rake db:migrate. I'm in favor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment