Created
December 14, 2012 19:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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