Mais conteúdo relacionado Semelhante a おすすめ gem (20) おすすめ gem2. gem とは?
• Ruby のライブラリをパッケージ化した
もの
• PHP でいう pear みたいなもの
• パッケージ管理システム自体は
RubyGems と呼ぶ
5. *** REMOTE GEMS ***
activerecord-jdbcmysql-adapter (1.2.2, 1.0.3 java)
activerecord-mysql-adapter-flags (0.0.3)
activerecord-mysql2-retry-ext (0.1.0)
activerecord-mysql2legacydb-adapter (0.2.0)
activerecord-mysql2spatial-adapter (0.4.2)
activerecord-mysqlspatial-adapter (0.4.1)
airblade-mysql_s3_backup (0.0.4)
aqueduct-mysql (0.1.0)
capistrano-mysqldump (1.06)
create_rails_mysql_db (0.2.3)
...
7. *** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.2.1)
actionpack (3.2.1)
activemodel (3.2.1)
activerecord (3.2.1)
activeresource (3.2.1)
activesupport (3.2.1)
addressable (2.2.8)
arel (3.0.0)
awesome_print (1.0.2)
...
13. 何がいいの?
• あの gem は開発環境には入っているけど、本
番環境に入っていないのでアプリが動かな
い!という問題を解消できる
• インストールするバージョンを固定できる
• gem 間の依存関係を解決してくれる
18. • 多機能な認証用ライブラリ
• OmniAuth と組み合わせることで
Facebook や Twitter などと OAuth 認証
することができる
• ちょっと規模が大きい気もする
• https://github.com/plataformatec/
devise
29. # app/models/ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :destroy, Post, user_id: user.id
end
end
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
# app/views/posts/edit.erb
<% if can? :destroy, @user %>
<%= link_to '削除', posts, method: :delete %>
<% end %>
32. • migration で enum 型を使用可能に
• これを使わなくても無理やり書けるが、
schema.rb が varchar(0) とかになるので
よろしくない
• https://github.com/electronick/
enum_column
34. • migrate ファイルに簡単に外部キー制約を記
述
• add_foreign_key(:comments, :posts)
• execute メソッドを使用すれば SQL でも書
けるがこちらのほうが楽
• https://github.com/matthuhiggins/
foreigner
36. • 論理削除
• カラムに deleted_at を追加し、モデルに
acts_as_paranoid と書くだけ
• https://github.com/goncalossilva/
rails3_acts_as_paranoid
45. • rake spec の起動遅すぎワロタ...
• DRb と呼ばれる分散オブジェクトプログ
ラミング用のサーバーに Rails をロードし
ておく
• 起動速すぎワロタ
• https://github.com/sporkrb/spork
50. • デプロイツール
• DSL で書ける
• ...が、慣れないと設定がだるい
• リモートサーバーでコマンドをたたける為、
デプロイ以外でも使用可能(何かをインストー
ルするとか)
• https://github.com/capistrano/capistrano
52. • p や pp よりオブジェクトを見やすく
console に表示してくれる
• カスタマイズ可能
• https://github.com/michaeldv/
awesome_print
Notas do Editor \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n