Skip to content

Instantly share code, notes, and snippets.

@gfguthrie
Created December 14, 2012 19:25
Show Gist options
  • Save gfguthrie/4287928 to your computer and use it in GitHub Desktop.
Save gfguthrie/4287928 to your computer and use it in GitHub Desktop.
Class to quickly make objects for the options_from_collection_for_select helper
# @example Quickly make objects for options_from_collection_for_select helper
# in myclass_helper.rb:
# def my_select_columns
# [ SelectOption.new(id: 1, name: 'first'), SelectOption.new(id: 2, name: 'second') ]
# end
#
# in myclass/action.html.haml:
# = select_tag :my_select, options_from_collection_for_select(my_select_columns, 'id', 'name', 1)
class SelectOption
attr_accessor :id, :name
def initialize(params={})
params.each do |attr, value|
self.public_send("#{attr}=", value)
end if params
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment