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
Post a Comment