Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peterconsuegra/countries_regions_and_cities_by_pete
An agile way to implement Countries, Regions, and Cities in a Ruby On Rails scaffold without the need to create additional tables
https://github.com/peterconsuegra/countries_regions_and_cities_by_pete
Last synced: about 2 months ago
JSON representation
An agile way to implement Countries, Regions, and Cities in a Ruby On Rails scaffold without the need to create additional tables
- Host: GitHub
- URL: https://github.com/peterconsuegra/countries_regions_and_cities_by_pete
- Owner: peterconsuegra
- Created: 2021-12-25T14:57:01.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-04T17:43:40.000Z (about 3 years ago)
- Last Synced: 2024-04-26T21:02:43.711Z (9 months ago)
- Language: Ruby
- Homepage:
- Size: 451 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Ruby On Rails Countries, Regions and Cities by Pete
An agile way to implement Countries, Regions, and Cities in a Ruby On Rails scaffold without the need to create additional tables
## Support
Ruby On Rails: 5, 6, 7
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'countries_regions_and_cities_by_pete'
```And then execute:
$ bundle install
## Usage
Let's create a example for a Place scaffold:1. Let's create a new rails app:
```ruby
rails new myapp
```2. Create the database:
```ruby
bundle exec rake db:create
```3. Go to the application directory in Terminal and run the following command to create a scaffold for the Place model:
```ruby
bundle exec rails g scaffold Place name:string description:text
```4. Add this line to your application's Gemfile:
```ruby
gem 'countries_regions_and_cities_by_pete'
```5. Go to your application's directory in Terminal and run:
```ruby
bundle install
```6. Go to the application directory in Terminal and run the following command to install the necessary code and files from the gem:
```ruby
bundle exec rake 'install_countries_regions_and_cities_by_pete[Place]'
```7. Add jQuery to your layout file: /app/views/layouts/application.html.erb
```html
```
8. Paste this code to your _form.html.erb file: /app/views/places/_form.html.erb
```ruby
<%= render partial: "shared/country_select_by_pete", locals: {model: form.object.class.name, label: "Country", selected: form.object.country} %>
<%= render partial: "shared/region_select_by_pete", locals: {model: form.object.class.name, label: "Region / State", selected_country: form.object.country, selected: form.object.region} %>
<%= render partial: "shared/city_select_by_pete", locals: {model: form.object.class.name, label: "City", selected_region: form.object.region, selected_country: form.object.country, selected: form.object.city} %>
```
9. Allow parameters (country,region and city) in your controller: /app/controllers/places_controller.rb```ruby
def place_params
params.require(:place).permit(:name, :description, :address, :country, :region, :city)
end
```Video Tutorial
===============Watch this video to see how it works
[![IMAGE ALT TEXT HERE](https://ozonegroup.co/countries_regions_and_cities.png)](https://www.youtube.com/watch?v=mSwfFtYE8HE)
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/peterconsuegra/countries_regions_and_cities. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/peterconsuegra/countries_regions_and_cities_by_peterconsuegra/blob/master/CODE_OF_CONDUCT.md).
## Code of Conduct
Everyone interacting in the CountriesRegionsAndCitiesByPeterconsuegra project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peterconsuegra/countries_regions_and_cities_by_peterconsuegra/blob/master/CODE_OF_CONDUCT.md).