Ruby on Rails: Sandboxed Console

I wish I knew about the --sandbox option of the rails console before:

~/Code/ruby/rails tutorial % bundle exec rails console --sandbox
Loading development environment in sandbox (Rails 3.0.5)
Any modifications you make will be rolled back on exit

1.8.7 :001 > Micropost.count
=> 1

1.8.7 :002 > mp = Micropost.create!(:content => "content", :user_id => User.first.id)
1.8.7 :006 > Micropost.count
 >=> 2

1.8.7 :007 > quit

~/Code/ruby/rails tutorial % bundle exec rails console --sandbox
Loading development environment in sandbox (Rails 3.0.5)
Any modifications you make will be rolled back on exit

1.8.7 :001 > Micropost.count
 => 1
1.8.7 :002 >

Everything you’ve done in sandbox mode will be rolled back after you quit the console.


comments powered by Disqus