Wednesday, October 31, 2012

Added message to Campfire chatroom for Capistrano deploys


# Gemfile
gem 'capistrano-campfire'
gem 'tinder'

# config/deploy.rb
require 'capistrano/campfire'
require 'tinder'

namespace :campfire do
  desc "Send a message to the campfire chat room"
  task :snitch do
    campfire = Tinder::Campfire.new YOUR_CAMPFIRE_ACCOUNT, :ssl => true, :token => YOUR_CAMPFIRE_TOKEN
    room = campfire.find_room_by_name YOURC_CAMPFIRE_CHATROOM
    snitch_message = fetch(:snitch_message) { ENV['MESSAGE'] || abort('Capfire snitch message is missing. Use set :snitch_message, "Your message"') }
    room.speak(snitch_message)
  end

  desc "Send a message to the campfire chat room about the deploy start"
  task :snitch_begin do
    set :snitch_message, "BEGIN DEPLOY [#{stage.upcase}]: #{ENV['USER']}, #{branch}/#{real_revision[0, 7]} to #{deploy_to}"
    snitch
  end

  desc "Send a message to the campfire chat room about the deploy end"
  task :snitch_end do
    set :snitch_message, "END DEPLOY [#{stage.upcase}]: #{ENV['USER']}, #{branch}/#{real_revision[0, 7]} to #{deploy_to}"
    snitch
  end

  desc "Send a message to the campfire chat roob about the rollback"
  task :snitch_rollback do
    set :snitch_message, "ROLLBACK [#{stage.upcase}]: #{ENV['USER']}, #{latest_revision[0, 7]} to #{previous_revision[0, 7]} on #{deploy_to}"
    snitch
  end
end

before :deploy do
  campfire.snitch_begin unless ENV['QUIET'].to_i > 0
end

after :deploy do
  campfire.snitch_end unless ENV['QUIET'].to_i > 0
end

Permission denied (publickey) error when trying to do cap deploy

My solution was to run in my terminal

ssh-add
Seemed like my there wasn't an identity associated with my ssh public key so Github rejected capistrano attempt to git clone from the deployment server.

Tuesday, October 30, 2012

Top 3 hosted CI (continuous integration) for Rails apps


Here's my summary of top 3 hosted solutions for Rails continuous integration are:

- https://semaphoreapp.com/features
- https://www.circleci.com/
- Tddium

Tddium looks very configurable and gives power to the commandline, eg. run builds from local console on branches. $15/mth for 10 worker hours.

http://docs.tddium.com/

CircleCI had good reviews and sounded like it runs builds really fast. Like Tddium, it's configurable via a yaml file. No official price plans on website but responded via twitter that theirs plans starts from $19.

http://blog.exceptional.io/news/circleci/

Semaphore selling point's their "simple stupid" approach to CI. Oauth via Github, add collaborators and boom. Runs are every git push and at a price of $14/mth, it seemed the cheapest of 'em lot.

https://semaphoreapp.com/features

My vote is for Semaphore since it's the cheapest and simplest to use for a small project.

Thursday, October 25, 2012

Update all associations of a Rails model


  @msg_thread.messages.update_all(status: 'read')

Tuesday, October 16, 2012

Ember.js gotcha - require handlebar.js

Require handlebar.js BEFORE ember.js

# in rails
//= require handlebars
//= require ember

Scope javascript variable in coffeescript so it's available in browser


App = Foo.bar

window.App = App

Rails scaffold only the controller resource


rails g scaffold_controller users

Wednesday, October 3, 2012

Customizing devise views & controllers

I find myself repeating and googling this far too many times...

# Generate the devise views
rails g devise:views

# Add customize views resource to route
devise_for :users, controllers: { registrations: "users/registrations" }

# Move views to new resource folder
git mv app/views/devise/registrations/ app/views/users/

# Add new custom devise controller
class Users::RegistrationsController < Devise::SessionsController

  def new
    @user = User.new
  end

  def create
    ...
  end

end

Cannot customize default devise views

DO NOT use Devise to generate scoped views.

rails generate devise:views users
Just use

rails generate devise:views