Ruby on Rails accessing back enum type in controller -


following product model:

class product < activerecord::base  enum status: {         disable: 0,         enable: 1     }  end 

in controller:

class productscontroller < applicationcontroller private         def set_product             @product = product.friendly.find(params[:id])             if(@product.status != "disable"){                 @products             } else {                 redirect_to root_path             }         end end 

here @product.status returning either disable or enable, how can use condition check product status? above @product.status != "disable" not working. thanks!!

when have defined enum create methods directly connect enum.

like disable?, enable?

class productscontroller < applicationcontroller private   def set_product     @product = product.friendly.find(params[:id])     if @product.disable?       @products     else       redirect_to root_path     end   end 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -