Railsプロジェクトのはじめかた(with Slim, RSpec)
プロジェクトの作成
mkdir ~/workspace/hoge_project
cd ~/workspace/hoge_project
bundlerでRailsインストール
bundle init
vi Gemfile
- Gemfile (railsの前のコメント取るだけ)
# A sample Gemfile
source "https://rubygems.org"
gem "rails"
- bundle install
bundle install --path vendor/bundle
railsプロジェクトを作成
bundle exec rails new .
- Overwrite Gemfile? (enter "h" for help) [Ynaqdh] ときかれたらYを押して続行
プロジェクト全体の設定
- .gitignore に以下を追加
/vendor/bundle
- Gemfileに以下を追加
gem 'slim-rails'
group :test do
gem 'rspec'
gem 'rspec-rails'
end
- config/application.rb
class Application < Rails::Application 内に以下を追加
(略)
module HogeProject
class Application < Rails::Application
config.generators.template_engine = :slim
config.generators.test_framework = :rspec
config.generators.stylesheets = false
config.generators.javascripts = false
config.generators.helper = false
(略)
end
end
-
Gemfileに追加したモジュールをインストール
bundle install
### コントローラを生成したときに slimファイルとspecファイルが生成されることを確認する
bundle exec rails g controller hoge index
=> 以下のようにslimファイルとspecファイルがcreateされればOK
create app/controllers/hoge_controller.rb
route get "hoge/index"
invoke slim
create app/views/hoge
create app/views/hoge/index.html.slim
invoke rspec
create spec/controllers/hoge_controller_spec.rb
create spec/views/hoge
create spec/views/hoge/index.html.slim_spec.rb
invoke assets
invoke coffee
invoke scss