Skip to content

Instantly share code, notes, and snippets.

@jumph4x
Created March 21, 2012 20:37
Show Gist options
  • Save jumph4x/2152664 to your computer and use it in GitHub Desktop.
Save jumph4x/2152664 to your computer and use it in GitHub Desktop.
manual rate_hash iteration for spree
#this is what Order#rate_hash outputs, roughly
sample_rate_hash = [{:id => 4, :name => 'ShippingMethod', :price => 24.55}]
# we take the array of hashes and for each one we create an HTML <option>, we show the user the name and the price, for value we store the shipping_method_id
# then we join all the html options into one string
# then we mark the string as safe for frontend
options = sample_rate_hash.map{|rate| content_tag(:option, "#{rate[:name]} #{rate[:price]}", :value => rate[:shipping_method_id])}.join.html_safe
# then we simply give that to select
select_tag :order, options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment