私はレール3.0.9を使用しており、認証のために工夫しています。今私は多相を使用する必要があるので、単一テーブルの継承を使用しようとしているので、私は2つのクラスを持っています:UserType1とUserType2は、Userクラスから継承しています。私は、ユーザーのタイプに応じて、そのDeviseインスタンスを正しくcurrent_userする必要があります。例えばdevise:instance単一のテーブル継承を使用しているcurrent_user
、
class User < ActiveRecord::Base
#devise and other user logic
end
class UserType1 < User
def get_some_attribute
return "Hello, my type is UserType1"
end
end
class UserType2 < User
def get_some_attribute
return "Hello, my type is UserType2"
end
end
In controller
class MyController < ApplicationController
def action
@message = current_user.get_some_attribute #depending the type using polymorphism
render :my_view
end
end
私も同じ問題を抱えています – maxiperez
ユーザテーブルに 'タイプ'カラムを追加しましたか?これがRails STIを動作させる理由です。 – Salil
私の恩恵を忘れて、 'current_user'はうまくインスタンス化されています。 –