Skip to content

Instantly share code, notes, and snippets.

@shin1ohno
Created April 2, 2012 16:35
Show Gist options
  • Save shin1ohno/2284839 to your computer and use it in GitHub Desktop.
Save shin1ohno/2284839 to your computer and use it in GitHub Desktop.
Rails project creation memo

Railsアプリケーションの生成

rspecを使うので、--skip-test-unit

rails new app_name -T --skip-test
rm public/index.html app/assets/images/rails.png

Gemfileに必要なものを追加してbundle

bundle

rspec

rails g rspec:install

OmniAuthの設定諸々(必要に応じてdeviceと使い分け or 併用)

OmniAuth用のUser ModelとSessions Controllerを用意、Sessions Controllerにcreateとdestroyを実装しておく

rails g model User provider:string uid:string name:string
rails g controller Sessions

User Modelにcreate_with_omniauthを実装

def self.create_with_omniauth(auth)
  create!do |user|
    user.provider = auth["provider"]
    user.uid = auth["uid"]

    if user.provider == "facebook"
       user.name = auth["info"]["name"]
    else
       user.name = auth["info"]["nickname"]
    end

  end
end

必要に応じてmigrationをいじってdb:migrate

rake db:migrate

初期化ファイル

#config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :developer unless Rails.env.production?
  provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
end

routes.rbを編集

match '/auth/:provider/callback', to: 'sessions#create'

View周り諸々の設定

twitter-bootstrap-railsの設定

rails g bootstrap:install

formtasticの設定

rails generate formtastic:install

config/initializers/formtastic.rbに追加

Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder

app/assets/stylesheets/application.cssに追加

*= require formtastic-bootstrap

unicorn

config/unicorn.rb

guard

spork --bootstrap
bundle exec guard init rspec
bundle exec guard init rails-assets
bundle exec guard init bundler
bundle exec guard init spork
bundle exec guard init livereload

livereloadのブロックを一番上にもっていく

このへんでgitしとく

git init
git add .
git commit -m "Project creation and basic setups"
git co -b new_branch

サーバとguardをスタート

bundle exec guard
rails s
# or bundle exec unicorn_rails -c config/unicorn.rb

モデルとか作る

rails g model ....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment