🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

countries_regions_and_cities_by_pete

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

countries_regions_and_cities_by_pete

bundlerRubygems
Version
0.3.5
Version published
Maintainers
1
Created
Source

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:

gem 'countries_regions_and_cities_by_pete'

And then execute:

$ bundle install

Usage

Let's create a example for a Place scaffold:

  • Let's create a new rails app:
rails new myapp 
  • Create the database:
bundle exec rake db:create
  • Go to the application directory in Terminal and run the following command to create a scaffold for the Place model:
bundle exec rails g scaffold Place name:string description:text
  • Add this line to your application's Gemfile:
gem 'countries_regions_and_cities_by_pete'
  • Go to your application's directory in Terminal and run:
bundle install
  • Go to the application directory in Terminal and run the following command to install the necessary code and files from the gem:
bundle exec rake 'install_countries_regions_and_cities_by_pete[Place]'
  • Add jQuery to your layout file: /app/views/layouts/application.html.erb
<script src='/countries_regions_and_cities_by_pete/jquery-3.6.0.min.js'></script>
  • Paste this code to your _form.html.erb file: /app/views/places/_form.html.erb
<div class="field" id="country_field">
  <%= render partial: "shared/country_select_by_pete", locals: {model: form.object.class.name, label: "Country", selected: form.object.country} %>
  </div>
<div class="field" id="region_field">
  <%= 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} %>
  </div>
 <div class="field" id="city_field">
  <%= 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} %>
  </div>
  • Allow parameters (country,region and city) in your controller: /app/controllers/places_controller.rb
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

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.

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.

FAQs

Package last updated on 04 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts