Tagged with

rails

Web Developer pro tip – LiveReload

I started doing quite a bit of HTML, CSS, Javascript, RoR development. As a long time developer using Flash we compile a swf and most IDEs launch the browser in order for you to view changes.

That small nugget can save you lots of development hours. Textmate is my editor of choice for Rails and Javascript these days. While it does have a “preview” browser it has some small issues. It does refresh but it only stays visible on a selected file. If you switch to another file you have to launch it again.

You will be doing yourself a huge favor by checking out “LiveReload”. This awesome and simple application allows you to set up lots of directories for web development. Placing some javascript on the page hooks up a single page to reload as files change but even better there is an extention for google chrome and ff and any time a file changes with in your web directory it will reload any page you have loaded within the browser for that project. A very small simple solution but one that is well worth the money.

The Web Developer Wonderland

(a happy land where browsers don’t need a Refresh button)

CSS edits and image changes apply live.

CoffeeScript, SASS, LESS and others just work.

Citizenship is granted through the Mac App Store.
Windows permanent residency issues are being worked out,
temporary stay already allowed.

Clear mongodb in 3 lines of code using Mongoid

As always I am learning more and more about ruby and rails. Recently I choose to take a stab at using Mongodb as my database and move away from using more traditional DBs such as Sqlite and Postgres.

It has been a little strange not having to run rake tasks such a migrate to setup new database tables and such. If you find yourself needing to clear out all the data in the database and you are using the Mongoid gem such as I am in your rails project then you can run the rails console and do the following to clear everything out. I find this useful if you have been developing and need to clear out all your test data.

Mongoid.database.collections.each do |collection|
      unless collection.name =~ /^system./
        collection.remove
      end
    end

Using Mongoid on Heroku with MongoHQ

If you are using Rails 3 and you want to use mongohq with heroku along with the mongoid gem then after you install mongohq on your heroku instance you will need to open or create preninitializer.rb  file and do the following.

require ‘uri’

if ENV[“MONGOHQ_URL”]
  mongo_uri = URI.parse(ENV[“MONGOHQ_URL”])
  ENV[‘MONGOID_HOST’] = mongo_uri.host
  ENV[‘MONGOID_PORT’] = mongo_uri.port.to_s
  ENV[“MONGOID_USERNAME”] = mongo_uri.user
  ENV[‘MONGOID_PASSWORD’] = mongo_uri.password
  ENV[‘MONGOID_DATABASE’] = mongo_uri.path.gsub(“/”, “”)
end

These environment variables should get picked up in the mongoid.yml file and configure everything to work correctly. Also make sure you add the uri: argument under production.

production:
  uri: <%= ENV[‘MONGOHQ_URL’] %> 
  host: <%= ENV[‘MONGOID_HOST’] %>
  port: <%= ENV[‘MONGOID_PORT’] %>
  username: <%= ENV[‘MONGOID_USERNAME’] %>
  password: <%= ENV[‘MONGOID_PASSWORD’] %>
  database: <%= ENV[‘MONGOID_DATABASE’] %>

Upgrading to Rails 3.1 step by step.

If you follow the RoR world at all you know that Rails 3.1.0 is about too launch. I like to stay on the bleeding edge of stuff like this so I jump right in and install beta releases. Of course if you have a big production app you should dip your toe in carefully when doing such things but I am still learning ruby and rails so I see doing things like this as a great opportunity to gain a little more knowledge about the language and framework.

First up OS X 10.6.6 is my preferred OS so I am speaking to all you Mac users. My setup by the end of this post will be running ruby 1.9.2 and Rails 3.1.0.rc2. My goal was to get it up and running and also to launch an existing rails app even if I fall back to using rails 3.0 for now, until I get time to migrate the app to the latest version.

A couple of issues I ran into where around sqlite3 drivers and also when installing ruby with RVM, and there are some function names with in the sqlite3 bundle that need to be changes. I am not going to go into great detail but rather point you in the direction buy supplying step by step links that I used after searching on ways to fix each issue I ran into.

Each resource will get you going and is ment to be followed in order. My guess is you will run into issues that I didn’t see but at least you will have a good start and wont have to hunt for some of the solutions like I did.

  1. Upgrade or install ruby 1.9.2 using RVM – http://bit.ly/mqoZps 
  2. Install pre-release Rails 3.1.0.rc2 or whatever version it is gem install rails –pre from the command line. (check rubyonrails.org for more info) 
  3. You may have to fix an issue with your sqlite3 bundle so read this post if you get an error when trying to use sqlite3 http://bit.ly/kLSrMZ 
  4. You will probably run into a driver issue with sqlite3 now that you are using ruby 1.9.2 so you will need to make sure that any projects are using 1.3.1 gem or higher by adding the following line to any projects gem file or just installing the latest gem fromt he command line like so. 

gem ‘sqlite3-ruby’, “>= 1.3.1”, :require => ‘sqlite3’

Read the following post for more info on the sqlite3 gem issue I ran into if you like. It’s addressing a windows user issue but the fix worked for me as well. http://bit.ly/ihiSgU

Unlock Amazing

I recently started working with the guys at driftlab and the experience has been awesome. It’s always great to work with a team of developers that are great at what they do. Working with them, I have gotten to keep my skills sharp with the flash development, but it has also afforded me the opportunity to do some server side development. The project that really allowed me to get my “feet wet” was the Quaker Oats Canada “Unlock Amazing” app for Facebook. Here is the French version for all my French Canadian friends. 

The app allows users to create custom bowls and store them in there Facebook gallary and also add there bowl to the over all count of bowls that users are creating. For each bowl created Quaker Oats is donating food to families in need. Pretty awesome projecte to get to work on. 

Nothing too special going on with the server side development. Just storing Url paths to images and making sure users can only register every seven days.

Anyway, I am 100% sold on using rails. It made development super fast and tones of resources out there when you need it. On top of that it’s great as a UI developer to have a platform that you can use that is fast and really easy to understand. 

Gemfile syntax highlight in TextMate

Quick tip that I found when searching to find out how to get syntax highlighting in your Gemfile if you are using TextMate Ruby on Rails bundle.

In Textmate, select the Bundles menu => Bundles editor

Select languages instead of show all.

Select the Ruby on Rails language within the Ruby on rails bundle

Change this line:

fileTypes = ( 'rb', 'rxml', 'builder' );

to this:

fileTypes = ( 'rb', 'rxml', 'builder', 'Gemfile' );

Go to Bundles => Bundles Editior => Reload Bundles.

Reopen your Gemfile and you should now be getting the syntax highlighting.