投稿

映画の半券

イメージ

Rails Devise認証のカスタマイズメモ

Deviseのデフォルトの認証ではDBに保存されているemail, passwordの項目で認証を行なっている。 例えば、DBにemail, passwordを別で認証する場合、カスタマイズが必要となる。 そのカスタマイズ方法を調査した内容を以下に記す。 ※omniauthを使った外部サイトで認証・callbackではないです。 バージョン情報  Rails 3.2.6  Devise 2.1.2 例  ・usersテーブルにログインユーザの情報を保持。  ・パスワードはDBに保持していない。(ここでは 'password' 固定) 1.認証処理の追加  Deviseでは認証処理はstrategyとして作成されている。  認証方法をカスタマイズするにはstrategyを新たに作成する。 ※以下の内容はDeviseのstrategy(database_authenticatable)を参考に、パスワード判定のみ変 更。 ・config/initializers/devise_strategies.rb require 'devise/strategies/authenticatable' module Devise module Strategies class CustomAuthenticatable < Authenticatable def authenticate! resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash) return fail(:invalid) unless resource if validate(resource){ password == 'password' } resource.after_database_authentication success!(resource) end end end end end Warden::Strategies....

映画の半券

イメージ
最近はヱヴァを観に来てる人が多い...

twitter-bootstrap-railsをサブディレクトリで動かす

twitter-bootstrap-railsをサブディレクトリで動かすとアイコンの読み込み先にサブディレクトリが含まれないので、やったことのメモ。 app/assets/stylesheets/bootstrap_overrides.css.lessのリネーム bootstrap_overrides.css.less を bootstrap_overrides.css.less .erb にリネーム bootstrap_overrides.css.less.erbを更新 @import "twitter/bootstrap/responsive"; // Set the correct sprite paths @iconSpriteAssetPath: asset-path('/twitter/bootstrap/glyphicons-halflings.png'); @iconSpritePath: `"<%= ActionController::Base.config.relative_url_root %>" + @{iconSpriteAssetPath}.replace('"', '')`; @iconWhiteSpriteAssetPath: asset-path('/twitter/bootstrap/glyphicons-halflings-white.png'); @iconWhiteSpritePath: `"<%= ActionController::Base.config.relative_url_root %>" + @{iconWhiteSpriteAssetPath}.replace('"', '')`; // Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines) // Note: If you use asset_path() here, your compiled b...

Ruby技術者認定試験 Gold 合格

イメージ
「Ruby技術者認定試験 Gold」合格しました。 一回落ちたし、

映画の半券

イメージ

Cloud Foundry サブディレクトリでアプリ公開

Cloud Foundryでアプリ公開するURLは <アプリ名>.<ドメイン名>になる。 READMEのサンプルでいうと env.vcap.me これを www.vcap.me/env のようにアプリ名のサブディレクトリでの公開はリバースプロキシを使用することで出来た。 READMEどおりにインストールした場合のnginx例: 変更前 ~/cloudfoundry/.deployments/devbox/deploy/nginx/nginx-0.8.54/conf/nginx.conf ・ ・ ・   upstream router_status {     server localhost:8081;   }   server {     listen       80;     server_name  _;     server_name_in_redirect off; ・ ・ ・ 変更後 ・ ・ ・   upstream router_status {     server localhost:8081;   }   server {     listen 80;     server_name www.vcap.me;     server_name_in_redirect off;     location /env {       proxy_pass http://env.vcap.me/;     }   }   server {     listen       80;     server_name  *.vcap.me;     server_name_in_redirect off;...