का उपयोग कर रहा रेल 3.0.9 का उपयोग कर रहा है और प्रमाणीकरण के लिए तैयार। अब मैं एकल टेबल विरासत का उपयोग करने की कोशिश कर रहा हूं क्योंकि मुझे बहुरूपता का उपयोग करने की आवश्यकता है, इसलिए मेरे पास दो वर्ग हैं: UserType1 और UserType2, जो उपयोगकर्ता वर्ग से प्राप्त होते हैं। मुझे उपयोगकर्ता के प्रकार के आधार पर वर्तमान डिवाइस का सही ढंग से deise उदाहरण की आवश्यकता है।चिंतन करना: उदाहरण के 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
आप उन तालिका में 'प्रकार' कॉलम में जोड़ लिया है गया है? यही रेलवे एसटीआई काम करता है। – Salil
मेरी बक्षीस को भूल जाओ, 'current_user' अच्छी तरह से तत्काल है। –