Showing posts with label rubyonrails. Show all posts
Showing posts with label rubyonrails. Show all posts

August 25, 2013

RailsでHaml(とRSpec)を使えるようにするメモ

GitLabのソースでも見ながら勉強しようかなーと思っていて、GitLabがHaml(とRSpec)を使っているので、メモです。

1. Gemfile に以下を追記
gem 'haml-rails'
2. bundle install を実行してコントローラを作成
$ bundle install
$ rails g controller index index
      create  app/controllers/index_controller.rb
       route  get "index/index"
      invoke  haml
      create    app/views/index
      create    app/views/index/index.html.haml
      invoke  test_unit
      create    test/controllers/index_controller_test.rb
      invoke  helper
      create    app/helpers/index_helper.rb
      invoke    test_unit
      create      test/helpers/index_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/index.js.coffee
      invoke    scss
      create      app/assets/stylesheets/index.css.scss
3. 生成された views/index/index.html.haml ファイルを確認
%h1 Index#index
%p Find me in app/views/index/index.html.haml
4. index#indexにアクセス
5. RSpec
Gemfile に以下を追記して、同じ要領でした。
gem 'rspec-rails'

August 15, 2013

Railsでscaffoldを実行してみる

今までRubyは開発系のツールで少し触っていた程度でしたが、今後、Railsも触っていく必要が出てきたので、とりあえずScaffold(とマイグレーション)を実行してブラウザからアクセスしてみるまでのメモです。
# railsアプリケーションの初期化
$ rails new rails_example

# scaffoldの実行
$ cd rails_example
$ rails generate scaffold User name:string email:string

# マイグレーションの実行
$ rake db:migrate
ソースを反映(デプロイ)して、ブラウザから /users にアクセス


ルーティングの一覧は、以下のコマンドで確認できました。
$ rake routes
   Prefix Verb   URI Pattern               Controller#Action
    users GET    /users(.:format)          users#index
          POST   /users(.:format)          users#create
 new_user GET    /users/new(.:format)      users#new
edit_user GET    /users/:id/edit(.:format) users#edit
     user GET    /users/:id(.:format)      users#show
          PATCH  /users/:id(.:format)      users#update
          PUT    /users/:id(.:format)      users#update
          DELETE /users/:id(.:format)      users#destroy
Chef + VagrantでApache + Passengerの環境構築に時間がかかりすぎた。。。