rake spec SPEC_OPTS="--seed 12345"
My Blog
rake spec SPEC_OPTS="--seed 12345"
Today we will use Ruby on Rails along with some Javascript libraries to code a few common patterns –
The Javascript library, jQuery.token-input, is great for quickly building a Javascript-based autocomplete solution. You have to do only three things to get started:
I am conducting a workshop on how to deploy Ruby on Rails apps on a (Ubuntu) virtual private computer (VPC.) We’ll be using AWS Free Tier instances (t1.micro) to do this. When you have a freshly initialized AWS Ubuntu instance, you have to install more than just the Apache server basics to get through the full installation. This post lists all the necessary steps.
I was using Resque::Mailer, and couldn’t get it to work. I had what I thought was the simplest possible configuration – in my mailer – **app/mailers/user_mailer.rb** – I had this:
class UserMailer < ActionMailer::Base include Resque::Mailer def alert_developers(u) mail(:to => "#{u.email} <#{u.email}>", :subject => "Hello").deliver end end
But I was getting nothing – no new queue being created in Redis, and certainly no mails being sent.
It wasn’t until I removed the Resque::Mailer that I realized what was going on. The Mailer was in fact failing because no SMTP from field had been set, but that error is eaten up by Resque::Mailer. When you are not using Resque::Mailer, the error shows up in the resque-web application and it’s easier to debug.
When I put in a default From field in my config/application.rb file, everything worked great:
config.action_mailer.default_options = {from: "me@myplace.com"}
Now you know!
At some point after you’ve started building your first Rails application, you are going to ask yourself, does this application work the way it’s intended to? If you aren’t asking this question, it means you aren’t a good enough application developer. No application can be built to be perfect, and the only way to get there is to make sure your tests are good enough.
The Rails framework has a lot of tools to help you build a comprehensive, and easy to undestand, set of tests. Surprisingly though, the testing framework in Rails is not nearly as intuitive as the basic development framework, so here are a few tips to get you started.
There’s one thing I’m beginning to not like about the Rails framework a little, and that’s the penchant that it has for making up names for concepts that already exist in programming languages.
If you have been programming in object-oriented frameworks for a while, you’d be surprised to know that Rails likes to call it “single table inheritance.” Why not just call it “class hierarchy” or maybe even “model hierarchy”?
So I’ve started testing my code now, and delved a bit into the world of RSpec, Capybara and BDD.
This will take a while to figure out but here are two things I learned that aren’t really described anywhere in the most popular tutorials on Rails testing:
I have been teaching myself Rails now and listening to many of Ryan Bates’ most excellent Rails Casts, about which I cannot say enough good things.
I figured there’s usually a small list of things that most web apps tend to need, and if you’re a beginner Rails programmer like myself, you have probably spent some time trying to learn how to put all this code in. In fact, if you have RailsCast religion like I do, you have been probably copy pasting it from Ryan’s tutorials, except now you need to build a new app that does some other cool thing and you can’t remember all the Devise, CanCan, DoorKeeper, OAuth magic you painstakingly put together the first time around.
And even if you know these gems inside-out like the logo of your favorite brand of yogurt, and can paste in their configurations with both hands cuffed, wouldn’t it be nice to have a simpler way to do it?
Well, now you do! Head on over to this Github repo and quickly get Devise, CanCan and OmniAuth (with two providers – Facebook and Twitter!) running in your app.*
Now with Rails4 updates! This post has been getting a lot of search engine love, so I’m working on making it as helpful as possible. Feel free to ask questions in the comments section!
I love Ryan Bates, and I love Railscasts! The Rails learning curve is significantly leveled down by these excellent tutorials, or at least it adds a very helpful set of railings to drag oneself up that hill by.
I’m trying to hook up Devise and Doorkeeper together to build an application that is going to expose its data via an API. If you, like me, are learning how to do this using Mr Bates’ excellent teachings, you will probably have listened to Railscast #209, and are in the middle of Railscast #353.
I thought I’d add some notes for future n00bs to consider, based on a few hiccups I had:
I am working on a Rails3 application, and learned some interesting gotchas today.
Rails
Git and Github
git remote set-url <your Github remote name> git@github.com:siruguri/Categorizer
I am sure I’ll learn more as I go along!