Welcome to Joe Meirow's Blog
Hi there! My name is Joe Meirow. I have many interests in my life and use this website to chronicle what I'm working on at the moment. The other purpose this website serves is that in chronicling what I am learning, I hope that it can be a source of information for you as well.
- Learning
- All things software development
- Writing
- Public speaking
My Rails Recipes
Tuesday, March 20, 2012
New! Dumping,delete,loading though A/R models from the command line. Click here to view.
Monday, March 19, 2012
New! RSpec for the COMPLETE BEGINNER! Click here to view.
Wednesday, March 14, 2012
I am going to TRY to write a post here every time I learn something new about Ruby/Rails.
This morning I wanted to add to my app's development environment a way to dump the database to a file or files and a way to restore the database with that backed up data at a later time. First let me say there is probably an "up to date" way of doing this with the current version of Rails (3.2.x), but let me also say that the documentation in the Ruby/Rails ecosystem is quite lacking.
So, I ended up going with basically the only thing I could find, a plug-in written by PeepCode guru Geoffrey Grosenbach. The plug in 'ar_fixtures' and is available as a plug_in at https://github.com/topfunky/ar_fixtures. Here are the things I had to learn this today to get this to work:
- To install a plugin, go to your Rails' app home/root directory and type in 'plugin install ' and then paste in the url of the plugin from github (yes, I am assuming the plugin is on github)
- ar_fixtures essentially is a Rake task with some supporting code. Once installed, you'll find that the vendor/plugins/ar_fixtures/tasks directory has an ar_fixtures.tasks file. Copy it to your Rails apps' 'lib/tasks' folder. A quick view of the top of your apps' Rakefile will reveal that this is where it looks for task definitions.
- Once I had this in place, I attempted dumping the data via the command line with Rake. 'rake -T' will list the available commands and once I copied the ar_fixtures.tasks file to lib/tasks, I could see that rake -T returned a few additional options, notably db:data:dump and db:data:load.
- Upon running the Rake command, however, I encountered a runtime error that RAILS_ROOT was an uninitialized constant. Searching for RAILS_ROOT on Google revealed that RAILS_ROOT is deprecated in Rails 3.x. I replaced RAILS_ROOT with '::Rails.root.to_s' throughout all of the plugin files and it now works as expected.
That's all for today!
Recent Entries
- Date validation, parsing and formatting. December 11, 2011
- Rails Recipe. November 30, 2011