Bulk update

Rails ActiveRecord – Batch Updates
http://apidock.com/rails/ActiveRecord/Base/update_all/class

Tag.where(:is_featured => true).each do |tag|
  tag.update_attribute(:is_featured, false)
end

これだとTagオブジェクトがロードされるのでメモリーを食ってしまうので直接Update文を実行したい

Rails RDocのActiveRecord::Relation#update_allに記述されている書き方

Tag.where({:is_featured => true }).update_all({ :is_featured => false })

第二引数に条件を付けられるのでこちらの方が簡潔

Tag.update_all({ :is_featured => false }, {:is_featured => true })

どちらも実行されるSQLは同じ

UPDATE `tags` SET `is_featured` = 0 WHERE `tags`.`is_featured` = 1

Railsのgeneratorの使い方がわからない

公式ドキュメント
A Guide to The Rails Command Line 1.3 rails generate
Getting Up and Running Quickly with Scaffolding

Scafold

$ rails g  scaffold Post title:string text:text
      invoke  active_record
      create    db/migrate/20130814020256_create_posts.rb
      create    app/models/post.rb
      invoke    test_unit
      create      test/unit/post_test.rb
      create      test/fixtures/posts.yml
      invoke  resource_route
       route    resources :posts
      invoke  scaffold_controller
      create    app/controllers/posts_controller.rb
      invoke    erb
      create      app/views/posts
      create      app/views/posts/index.html.erb
      create      app/views/posts/edit.html.erb
      create      app/views/posts/show.html.erb
      create      app/views/posts/new.html.erb
      create      app/views/posts/_form.html.erb
      invoke    test_unit
      create      test/functional/posts_controller_test.rb
      invoke    helper
      create      app/helpers/posts_helper.rb
      invoke      test_unit
      create        test/unit/helpers/posts_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/posts.js.coffee
      invoke    scss
      create      app/assets/stylesheets/posts.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

Controller

$ rails generate controller admin/Users

Model

Rspec