iam is just asking for yourself, what is the best solution to my problem
Here are my models:
class products & lt; ActiveRecord :: Base is_mind: Prices, class_name = & gt; Accepts for "Product Process": _ Extra_AT_products_: Product product ending in prices & lt; ActiveRecord :: Base is_to: Product Termination Controller
Making DIFE @product = Product. New (Param [: Products]) @ Product ... and What do I have to do to prevent all product profiles from being saved when product_price.value == zero or product_price.value == 0.0 -
before_save ProductPrice in the hook. Return false will rollback for the whole transaction, not what I want to do. I just want to "kick" all the values with value == 0 or value == zero -
before calculating all the price_images [... ] and call Product.new (from params [: product]) It seems that the way of rail is not good ... -
after the product . New (params [: Products]) Repeat at all prices and remove them from the array. But the argument should be correct in my model? I just do not want to repeat myself to every controller who creates new prices ... Can anyone tell me the best solution for this? Is the railroad way?
Thank you!
Do you want it to be called a verification hook, something like this: < Pre> class product copy & lt; ActiveRecord :: Base is_to: Product Valid: Price ,: Numerology = & gt; {: Big_this = & gt; 0.0} end Look at other ways that you would like to do it with better control.
To avoid adding these invalid values in the first place, you can remove them from hashed attributes such as nested attributes:
class product & lt; ActiveRecord :: Base Df self.clean_attributes! (Product_params) product_prices = product_params ['prices'] || [] Product_prices.reject! {| Price | Price ['value'] To_f == 0 Rescue Truth} End-end product. China_tributes! (Param [: Products]) Products. New (Param [: Products])
Comments
Post a Comment