SendGridでメールを送信する

1. mailerを作成

$ rails generate mailer UserNotifier

app/mailers/usernotifier.rb

class UserNotifier < ActionMailer::Base
  default :from => 'any_from_address@example.com'

  # send a signup email to the user, pass in the user object that   contains the user's email address
  def send_signup_email(user)
    @user = user
    mail( :to => @user.email,
    :subject => 'Thanks for signing up for our amazing app' )
  end
end

2. templateを作成
app/views/Usernotifier/send_signup_email.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Thanks for signing up, <%= @user.name %>!</h1>
    <p>Thanks for joining and have a great day! Now sign in and do
awesome things!</p>
  </body>
</html>

3. SendGridを利用するように設定
config/environment.rb

ActionMailer::Base.smtp_settings = {
  :user_name => 'your_sendgrid_username',
  :password => 'your_sendgrid_password',
  :domain => 'yourdomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

4. UserNotifier.send_signup_email(@user).deliverなどの様にして呼び出す。
app/controllers/users_controller.rb

class UsersController < ApplicationController
  def create
    # Create the user from params
    @user = User.new(params[:user])
    if @user.save
      # Deliver the signup email
      UserNotifier.send_signup_email(@user).deliver
      redirect_to(@user, :notice => 'User created')
    else
      render :action => 'new'
    end
  end
end

Rubyを絵文字で書けるactive_emoji

sferik/active_emoji · GitHub

子どもや英語を知らない人のために、Rubyを簡単に読み書き出来るようにするのが目的のプロジェクト。

Ruby on Railsに組み込まれて良いように、active_emojiと命名したようです。

PRの際は、commit messageは絵文字で書いてとのことです。


こういうのも面白いですね

SVGアイコンを簡単に追加できるevil-icons

Githubのrepository
outpunk/evil-icons · GitHub

Evil Icons
にあるアイコンを利用できます。

f:id:nafu003:20141214235919p:plain

使い方は簡単

gem 'evil_icons'

bundle install

cssでrequireする。

//= require evil-icons

テンプレートファイル、レイアウトファイルでevil_icons_spriteをrenderする

<%= evil_icons_sprite %>

helperを利用してhtmlを生成出来ます。

<%= evil_icon 'ei-search' %>
<%= evil_icon 'ei-arrow-right', size: :m %>
<%= evil_icon 'ei-envelope', size: :l, class: "custom-class" %>

GithubをTerminalから操作するHubコマンド

homebrewでhubコマンドをインストールします。
github/hub · GitHub

$ brew install hub

それぞれコマンドを実行すると、>以降のコマンドが実行されます。

$ hub clone schacon/ticgit
> git clone git://github.com/schacon/ticgit.git

$ hub clone -p schacon/ticgit
> git clone git@github.com:schacon/ticgit.git

$ hub clone resque
> git clone git@github.com/YOUR_USER/resque.git

他にも、Pull Requestを作成出来たり

$ git pull-request

簡単にPull Requestのブランチを作成出来ます。

$ git checkout https://github.com/defunkt/hub/pull/73
> git remote add -f -t feature mislav git://github.com/mislav/hub.git
> git checkout --track -B mislav-feature mislav/feature

$ git checkout https://github.com/defunkt/hub/pull/73 custom-branch-name

最新のRspec Syntaxに変換してくれるTranspec

変換面倒だなーっと思っていたら、あった!

yujinakayama/transpec · GitHub

ありがとうyujinakayamaさん!

// transpecをインストール
$ gem install transpec
// transpecコマンド実行->Rspecを変換
$ transpec
// テストが通るか確認
$ bundle exec rspec
// テストが通ったら、自動生成のシンタックス変換情報をコミットメッセージに含める。
$ git commit -aeF .git/COMMIT_EDITMSG