Skip to content

Commit

Permalink
Merge pull request #62 from romaingweb/except_countries
Browse files Browse the repository at this point in the history
Discard countries from options with :except
  • Loading branch information
stefanpenner committed Jun 28, 2014
2 parents ad53059 + 82c27a2 commit 20b9ef1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -45,6 +45,12 @@ Supplying only certain countries:
country_select("user", "country", only: ["GB", "FR", "DE"])
```

Discarding certain countries:

```ruby
country_select("user", "country", except: ["GB", "FR", "DE"])
```

Supplying additional html options:

```ruby
Expand Down
6 changes: 6 additions & 0 deletions lib/country_select/tag_helper.rb
Expand Up @@ -39,6 +39,10 @@ def only_country_codes
@options[:only]
end

def except_country_codes
@options[:except]
end

def country_options
country_options_for(all_country_codes, true)
end
Expand All @@ -48,6 +52,8 @@ def all_country_codes

if only_country_codes.present?
codes & only_country_codes
elsif except_country_codes.present?
codes - except_country_codes
else
codes
end
Expand Down
7 changes: 7 additions & 0 deletions spec/country_select_spec.rb
Expand Up @@ -91,4 +91,11 @@ class Walrus
t = builder.country_select(:country_code, only: ['DK','DE'])
expect(t).to eql(tag)
end

it "discards some countries" do
tag = options_for_select([["United States of America", "US"]])
walrus.country_code = 'DE'
t = builder.country_select(:country_code, except: ['US'])
expect(t).to_not include(tag)
end
end

0 comments on commit 20b9ef1

Please sign in to comment.