If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
This is a quick screencast on how to use Backbone.js with a Ruby on Rails application. The screencast covers the simple example of submitting a form, saving the data to the database, and displaying the records in a table. The repo for the backbone-demo app I created for the screencast is on github. [UPDATE: if you are using Backbone 0.5.x make sure you change the word refresh to reset.]
I recently started using Backbone.js and have found it to be extremely useful for keeping my Javascript organized. One of the benefits of using Backbone that I didn’t realize until later is that it makes you start building a RESTful API without you even focusing on that as an outcome. Awesome.
One of the gotchas (which is covered n the Backbone.js site) is that Rails returns a JSON object that looks like this:
{ dog: { name: “Fido”, age: “2″ }}
While Backbone just wants to see:
{ name: “Fido”, age: “2″ }
In order to get Rails to play well with Backbone you need to tell Rails not to return the root in the JSON return. This is accomplished by adding the following line to an initializer.
ActiveRecord::Base.include_root_in_json = false
Backbone.js is really great stuff and I look forward to using it more in my applications. You should check it out if you haven’t already.
There are many sites and applications that begin their lives as “invite only.” This can be a very effective method of creating a sense of scarcity and at the same time build in a certain amount of curation to your user base. A good current example of a site that is still invite only is Dribble, a site for designers to share their work. The QA site Quora began as an invite only application but recently opened its doors to all comers.
In the Ruby on Rails world the current User authorization hotness is Devise, a gem created by José Valim of Plataformatec (see his great new book here: Crafting Rails Applications). Devise has a great community around it and is built to be modular, only use what you need. One of the pieces that it does not include is a method for sending invitations to new users and this is where the gem devise_invitable by Sergio Cambra comes in with the save.
One of the features that is really useful in an invite only world is to set how many invitations a User is allowed to send. In the Readme on github devise_invitable says that it accomplishes this with the invitation_limit field, the only problem with this piece of documentation is that it refers to something that is not in the current stable release of the devise_invitable gem, which is v0.3.6. To get the added capability of using invitation_limit, invited_by_id, validate_on_invite and invite_key you need to use at least v0.4.rc5. This release candidate currently relies on Devise v1.2.0 so your Gemfile should include the following:
If you are installing Devise for the first time then you should follow the instructions in the Readme here to get it setup, but before you run “rake db:migrate” you should add the line t.invitable to the ####_devise_create_users.rb migration. If you are adding devise_invitable to an app that already has Devise configured then you will need to create a migration that will add the missing fields to your Model. This migration would look like this:
Before you run this migration you should know how the invitation_limit is set in case you decide to handle things differently. To set the default number of invitations that a User can send you will uncomment/add the line config.invitation_limit = 5 to the initializers/devise.rb file (don’t forget to restart your server when in development to apply changes to config). The only drawback to this method by itself is that the number of invitations a User has is not set until they send their first invitation. This means that if you want to display how many invitations a User has left before they send their first one by referencing current_user.invitation_limit it will not display anything until after they have sent their first invitation at which point this would now be equal to 4. If you want to avoid this inconvenience you can change the line in the migration to add a default number for the invitation_limit when a user is created.
t.integer :invitation_limit, :default => 5
If you use this method then you still need to uncomment/add the config.invitation_limit line to your devise.rb initializer but it does not matter what number you set it to as long as it is greater than zero.
Compass is a Ruby gem that provides a stylesheet authoring framework based on Sass. It is an awesome way to generate CSS. I ran into some trouble getting my Ruby on Rails application to run on Heroku until I cam across a Gist by Michael van Rooijen which I have added to a bit to [...]
word-spacing I have never seen this CSS tag before today, but it turns out it is useful for a number of different things. Its primary usage is for, as the name suggests, setting the space between words in such things as p (paragraph) elements. The usage that I found for it was to remove the [...]
I recently needed to schedule delayed tasks in a web app that utilizes the Twilio SMS API, this is a discussion of how I handled that situation. My plan was to host my app on Heroku as I normally would until I realized that using the delayed_job gem on Heroku was where you had to [...]
The Daily will fail because it is not any better than USA Today’s, The Wall Street Journal’s, Wired’s, or ANY of the other magazine/newspaper’s apps. If I have to see a spinner for more than 10 seconds I will close your app. If I have to see one for more than 20-30 seconds I will [...]
This past Friday I quit my job as a Spine sales representative and starting Monday will be pursuing my dream of co-founding an internet startup company. One of the few things I didn’t like about the old job was that I couldn’t really talk about it in a public forum, like a blog. Being a [...]
[UPDATE: Please do not take this post as a recommendation for you to try to do what we did. Thanks, hope you enjoy!] A few years ago I ran the San Francisco marathon without training and finished it in 4 hours and 28 minutes. Most people don’t believe me when I tell them I did [...]
The Verizon iPhone is launching for current Verizon customers on Feb 3rd and I will not be one of the people in line to get it. I have an iPad and I am addicted to it so don’t call me an Android fanboy when I tell you that the number one reason I don’t want [...]
Competition is inevitable. If you are in a job in which you never feel as though you are competing with another entity, then: 1. You are in a monopoly, and 2. Your job will eventually become exceedingly boring. Many people think that they don’t like competition or that they are not competitive people, but that [...]