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

Overriding/Extending Country class with custom methods #506

Closed
exocode opened this issue Mar 7, 2018 · 4 comments
Closed

Overriding/Extending Country class with custom methods #506

exocode opened this issue Mar 7, 2018 · 4 comments

Comments

@exocode
Copy link

exocode commented Mar 7, 2018

Hi there, I wanna be able to extend the Country class by my custom methods.
But it seems Ruby/Rails is taking the Country class from the gem and not from my models.

Creating a country.rb in my app/models directory with the following content:

require "countries/version"

require 'iso3166'
require 'countries/mongoid' if defined?(Mongoid)

class Country < ISO3166::Country

  @country_index = []

  def to_s
    self.name
  end
  
  def subdivision_index
       # my content here
      puts "TEST"
  end

Calling

c = Country.search("AT")
c.subdivision_index

raises an error

c.subdivision_index
NoMethodError: undefined method `subdivision_index' for #<Country:0x007fe910800bc8>
Did you mean?  subdivisions

How can I achieve that?

The reason is, that I wanna save all countries in a db and make them searchable via ElasticSearch.
Thank you!

@rposborne
Copy link
Collaborator

Hm.

  1. What version are you running on?
  2. Are you requiring the global adapter in your gemfile?

@exocode
Copy link
Author

exocode commented Mar 8, 2018

Hm it seems "countries" gem had some progress in the last years :-)
I am using a custom branch, with some subdivisions added by myself. In order to switch to the actual hexorx version all of these subdivisions should be merged into the "original" one (yours). Is that possible to make a pull request? (all my added stuff is conform to the one of hexorx)

@rposborne
Copy link
Collaborator

@exocode We always accept PR's for new content, as long as it's valid, and not political charged.

@rposborne
Copy link
Collaborator

@exocode going to close this. Please reopen if you still need help on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants