Projeto: Vermelho

logs of development
スポンサーサイト

一定期間更新がないため広告を表示しています

| - | | - | -
overrideしたいdeviseのcontrollerが複数あるときのrouteの書式
config/routes.rb

devise_for :user, :controller => { :omniauth_callbacks => 'users/omniauth_callbacks', :registrations => 'users/registrations' }

http://stackoverflow.com/questions/3546289/override-devise-registrations-controller
http://stackoverflow.com/questions/8019745/rails-beta-invitations-overriding-devise-registration-controller
| Pg_Rails | 15:02 | comments(0) | trackbacks(0)
deviseを使っている場合でユーザ登録を停止するとき
:registerbleをコメントアウトする(sign_upまが無効になる)
http://www.tamrable.info/?p=432
| Pg_Rails | 17:57 | comments(0) | trackbacks(0)
DeviseとRails_adminで管理者権限をつける
まず、DeviseでAdminモデルを作る.

http://atotok.net/note/rails/?Devise%A4%C7%B4%C9%CD%FD%BC%D4%A4%F2%C4%C9%B2%C3


Deviseで2種類のロールを利用できるように、通常のユーザーとは別に管理者を追加出来るようにする。

Adminモデルを作成

$ rails generate devise Admin
      invoke  active_record
      create    db/migrate/20111226100548_devise_create_admins.rb
      create    app/models/admin.rb
      invoke    test_unit
      create      test/unit/admin_test.rb
      create      test/fixtures/admins.yml
      insert    app/models/admin.rb
       route  devise_for :admins

Adminモデルが作成される

class Admin < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

20111226100548_devise_create_admins.rb

class DeviseCreateAdmins < ActiveRecord::Migration
  def change
    create_table(:admins) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :admins, :email,                :unique => true
    add_index :admins, :reset_password_token, :unique => true
    # add_index :admins, :confirmation_token,   :unique => true
    # add_index :admins, :unlock_token,         :unique => true
    # add_index :admins, :authentication_token, :unique => true
  end

end

routes.rbに下記の行を追加

  devise_for :admins

adminsにはnameがないので、field :name, :type => String, :default => ""を追加しておく(viewでエラーになる)
続きを読む >>
| Pg_Rails | 14:49 | comments(1) | trackbacks(0)
image_tagで最大サイズを指定する(cssを出力)
 http://stackoverflow.com/questions/1963181/image-tag-doesnt-work-after-migration-rails-2-0-2-to-2-3-5

image_tag(IMAGE-PATH, :style => 'max-height: 100px; max-width: 100px')
| Pg_Rails | 00:27 | comments(0) | trackbacks(0)
form_tagによるモデルに関連しないフォーム(検索とか)
 http://www.geekzshu.com/rails/1284
| Pg_Rails | 20:26 | comments(0) | trackbacks(0)
PROFILE
CATEGORIES
LINKS
CALENDAR
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      
<< March 2024 >>
SELECTED ENTRIES
ARCHIVES
モバイル
qrcode
SPONSORED LINKS