ruby on rails - passing parent id into hash for options for select -
I have a method that takes two columns from the DELIVERYCOST database and the column 'title' group Under
'Time' . It turns into a hash
def self.titles_by_timing self.pluck (: id,: time, title: .group_by (& amp;: first) .each {| _, v | V.map! (End: Final)} and Delivery Coast. Titus_by_timing => {"Install" => [["Luton Day (07: 00-07: 00)", "LWB Day (07: 007: 00), "Luton Overtime (7am-7am)", "LWB Overtime", "Assistance Day (7am - 7pm)", "Assistant Overtime"], "Analyze" => ; ["Luton Day (07: 00-07: 00)", "LWB Overtime", "Lutton Overtime (7am-7am)", "Assistance Day (07: 00-07: 00)", "H Lupter Overtime "]," Fuel "=> [" Consonance Charge "," Fuel in London Zone 1-2 "," Fuel in London Area 3-4 "," Fuel to Mileage (outside M2)]} This work is section by form for distribution cost
= f.select: delivery_cost_id, option_groups_from_collection_for_select (DeliveryCost.titles_by_timing, time, title, : ID) Because the delivery costs of the cans are related to the delivery cost, and the delivery costs have many job delivery costs, I need to pass the ID. Delivery costs jobs to build the Union make an example, but I'm having great difficulty in doing so. How can I do this, am I expanding on my current method?
Help is highly appreciated.
class = "text" itemprop = "text">
It looks like DeliveryCost.titles_by_timing already, take all the heavy lifting You should use grouped_options_for_select instead of option_groups_from_collection_for_select
check
Update: ..
:
def self.titles_by_timing Do self.all.each_with_object (Hash.new ([]). Delivery_cost, classified | [Delivery_cost.title] | = [[Delivery_cost.id, delivery_cost.timing]] End End Keep in mind that this method may perform poorly due to loading all objects in memory. If this is a problem, you can try handing over some caching, memoisation or expensive queries to the database.
Comments
Post a Comment