Created
June 16, 2012 21:41
-
-
Save Hampei/2942566 to your computer and use it in GitHub Desktop.
Form helper for serialised attributes of type array-of-hashes.
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
module ActionView | |
module Helpers | |
class FormBuilder | |
# - f.fields_for_array_of_hashes :links do |lnk| | |
# .item | |
# = lnk.text_field :name | |
# = lnk.text_field :url | |
def fields_for_array_of_hashes(record_name, record_object = nil, options = {}, &block) | |
@object.send(record_name).each do |e| | |
e = OpenStruct.new(e) | |
def e.to_s; ''; end | |
@template.concat fields_for("#{record_name}[]", e, options, &block) | |
end | |
'' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment