Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Added label as a field for multiparameter_field #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/meta_search/helpers/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ def multiparameter_field(method, *args)
defaults = has_multiparameter_defaults?(args) ? args.pop : {}
raise ArgumentError, "No multiparameter fields specified" if args.blank?
html = ''.html_safe
fields_count = 0
args.each_with_index do |field, index|
type = field.delete(:field_type) || raise(ArgumentError, "No :field_type specified.")
cast = field.delete(:type_cast) || ''
opts = defaults.merge(field)
field_name = opts[:name] || method.to_s + "(#{fields_count + 1}#{cast})"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably put the fields_count line before this one and then not use +1 on this line.

html.safe_concat(
@template.send(
type.to_s,
@object_name,
(method.to_s + "(#{index + 1}#{cast})"),
field_name,
objectify_options(opts))
)
fields_count += 1 unless type == :label
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops too far indented.

end
html
end
Expand Down Expand Up @@ -163,4 +166,4 @@ def has_multiparameter_defaults?(args)
end
end
end
end
end