Learned a lot today.
hit a lot of bugs too
reload!doesn’t reload the console in 3.0.0 and 3.0.4
sudo gem update rails to update rails, and got an error needed to be worked around (by going to directory cd /Library/Ruby/Gems/1.8/gems/rails-3.0.4/ and creating the ‘lib’ directory). Probably better to use
bundle update rails instead…
Believe it or not, I had not added any class members before today, since rails does this for you from your DB schema.
Rails has some useful
to_json functionality, but they assume model objects. If you just want to parse from JSON into a plain hash, you can use the JSON gem. Yahoo has a decent example of making a HTTP call to a REST API in ruby, and the relevant API docs are useful too.
If you want to share code between controllers, helpers are not the way, as rails designates them for Views. You could create stock standard modules, but since everything inherits from ApplicationController, I think that’s not a bad place to put stuff.
Appending objects to arrays is easy, with the << operator.
Updating rails on the server is straight forward with capistrano, as long as you
require "bundler/capistrano" in your deploy.rb. Simply:
#from the project directory... bundle update rails # now edit the projects Bundle file and update the referenced version of rails bundle package # package up the updates for version control. ref: http://www.ruby-forum.com/topic/216091 git commit -a # commit the package cap deploy # since you committed the bundle the gems will now be available on the server cap deploy:migrate # if you have any db changes...
An interesting day of learning. Those API bugs stumped me for a bit – as being new to rails, I often first assume that the mistake is my own. But they are nothing in the face of just how powerful Rails is. One great example is how capistrano behaved when I hadn’t done the bundle update and commit. I was deploying to staging – so no worries even if it did break – but it basically realised that Rails 3.0.4 wasn’t available on the server (specifically, not available in my bundle – as bundled gems are no longer server-wide, which itself is awesome) and rolled back the deploy. Given that my method of deploying PHP was (and still is) using FTP uploads… this level of automation and environment sanitiy checking is unreal. In fact, the last PHP project I deployed was developed on a new version of PHP but running on a slightly older one (thanks to RHEL…). Rather than gracefully telling me that the environment wasn’t correct (as per rails with capistrano), I had to execute every line of code to see which ones failed…