Posts

Showing posts from December, 2021

Comparison between &&= and ||=

&&=    ||= Example 1 x=5 x=5 y=7 y=7 x&&=y x||=y X=7 x=5 y=7 y=7 Example 2 x=nil x=nil y=7 y=7 x&&=y x||=y x=nil x=5 y=7 y=7 Example 3 x=5 x=5 y=nil y=nil x&&=y x||=y x=nil x=5 y=nil y=nil

Difference between was, before_last_save, changed and changed?

  was: in the update action before update record if you want previous price not updated price then you should use @product.price_was before_last_save:   in the update action after update record if you want previous price not updated price then you should use @product.price_before_last_save changed?:   if you want to check your object is update or not? OR any value of object is updated or not then user this function.(Eg. @product.changed?) changed: if you want to check  what fields is updated  (Eg. @product.changed)

Standard of Code Sequence of model

 class Model < ActiveRecord::Base    #all mixins    include Something    extend Something     #other stuff    acts_as_taggable    paginates     #associations    has_many :something    belongs_to :something_else     #validations    validate_presence_of :something     #scopes    scope :something     #instance methods    def instance_method    end     #class methods    def self.method    end     #private methods    private    def method2    end End