Rails Change record values -


i have record in postgresql of user status boolean , attributes "true" , "false". want show "true" "active , "false" "inactive". how do query or thing add in model.

controller:

     def index      @users = user.reorder("id asc").page(params[:page]).per_page(10)      @count = 0      end  

model:

    class user < activerecord::base     has_many :orders     has_many :order_statuses       attr_accessible :first_name, :last_name, :email, :password,   :password_confirmation, :code       validates :first_name, presence: true      validates :last_name, presence: true      valid_email_regex = /\a[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i       validates :email, presence: true, format: { with: valid_email_regex },          uniqueness: { case_sensitive: false }      validates :password, length: { minimum: 6}      has_secure_password     before_save { self.email = email.downcase }      before_create :create_remember_token      def user.new_remember_token     securerandom.urlsafe_base64     end      def user.encrypt(token)     digest::sha1.hexdigest(token.to_s)     end       private       def create_remember_token      self.remember_token = user.encrypt(user.new_remember_token)       end         end 

add method in model, , when call @user.status, show 'active' or "inactive".

def status   self.status?  ?  "active" : "inactive" end 

hope, help. thanks


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -