Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rails 5 support #61

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
49 changes: 36 additions & 13 deletions lib/carmen/rails/action_view/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def region_options_for_select(regions, selected=nil, options={})
end

main_options = regions.map { |r| [r.name, r.code] }
main_options.sort!{|a, b| a.first.to_s <=> b.first.to_s}
main_options.sort! { |a, b| a.first.to_s <=> b.first.to_s }
main_options.unshift [options['prompt'], ''] if options['prompt']

region_options += options_for_select(main_options, selected)
Expand Down Expand Up @@ -172,14 +172,14 @@ def instance_tag(object_name, method_name, template_object, options = {})

def determine_parent(parent_region_or_code)
case parent_region_or_code
when String
Carmen::Country.coded(parent_region_or_code)
when Array
parent_region_or_code.inject(Carmen::World.instance) { |parent, next_code|
parent.subregions.coded(next_code)
}
else
parent_region_or_code
when String
Carmen::Country.coded(parent_region_or_code)
when Array
parent_region_or_code.inject(Carmen::World.instance) { |parent, next_code|
parent.subregions.coded(next_code)
}
else
parent_region_or_code
end
end
end
Expand Down Expand Up @@ -207,13 +207,36 @@ def to_region_select_tag(parent_region, options = {}, html_options = {})

value = options[:selected] ? options[:selected] : value(object)
priority_regions = options[:priority] || []
opts = add_options(region_options_for_select(parent_region.subregions, value,
:priority => priority_regions),
opts = add_options(region_options_for_select(parent_region.subregions, value,
:priority => priority_regions),
options, value)
select = content_tag("select", opts, html_options)
if html_options["multiple"] && options.fetch(:include_hidden, true)
tag("input", :disabled => html_options["disabled"], :name => html_options["name"],
:type => "hidden", :value => "") + select
tag("input", :disabled => html_options["disabled"], :name => html_options["name"],
:type => "hidden", :value => "") + select
else
select
end
end
end
end
end

if Rails::VERSION::MAJOR == 5
Copy link
Author

Choose a reason for hiding this comment

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

this is there changes for rails 5 support, others changes are automatic code formate by ide

Copy link

Choose a reason for hiding this comment

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

I suggest you get rid of the automatic code format thing, because it is not functional. If there is any code to clean up you should do it at another time or at least in a separate commit

module Tags
class Base
def to_region_select_tag(parent_region, options = {}, html_options = {})
html_options = html_options.stringify_keys
add_default_name_and_id(html_options)
options[:include_blank] ||= true unless options[:prompt]

value = options[:selected] ? options[:selected] : value(object)
priority_regions = options[:priority] || []
opts = add_options(region_options_for_select(parent_region.subregions, value, :priority => priority_regions), options, value)
select = content_tag("select", opts, html_options)
if html_options["multiple"] && options.fetch(:include_hidden, true)
tag("input", :disabled => html_options["disabled"], :name => html_options["name"],
:type => "hidden", :value => "") + select
else
select
end
Expand Down