How to loop through attributes in rails controller params -
i have has_many relationship , want loop field on each of items link main model (ingredients on recipe). im trying in before_filter can parse users input correctly want. how can set loop params want
the request parameters in rails accessible via params hash. can loop on hash using iterator.
params.each |k,v| puts "#{k}: #{v}" end as parsing user's input, not in before_filter method. gave example below of converting input such "1 1/2" 1.5. try this:
ingredient.rb:
# amount :decimal (assuming column exists on ingredients table) def humanized_amount amount.humanize! end def humanized_amount=(value) amount = cast_humanized_value_to_decimal(value) end then use humanized_amount attribute form input. suggestion. there's not right answer.
Comments
Post a Comment