Ruby On Rails Google Maps By Pete
An agile way to implement Google Maps geolocation in a Ruby On Rails scaffold
Support
Ruby On Rails: 5, 6, 7
Installation
Add this line to your application's Gemfile:
gem 'google_maps_by_pete'
Go to your application's directory in Terminal and run the command:
bundle install
Usage
Let's create a example for a Place scaffold:
- Let's create a new rails app:
rails new myapp --database=postgresql
- Create the database:
bundle exec rake db:create
- Go to your application's directory in Terminal and run the command:
bundle exec rails g scaffold Place name:string description:text
- Add this line to your application's Gemfile:
gem 'google_maps_by_pete'
- Go to your application's directory in Terminal and run:
bundle install
- Go to your application's directory in Terminal and run the command:
ruby bundle exec rake 'install_google_maps_by_pete[Place]'
- Add jQuery to your layout file: /app/views/layouts/application.html.erb
html <script src='/google_maps_by_pete/jquery-3.6.0.min.js'></script>
- Add maps.css to your layout file: /app/views/layouts/application.html.erb
html <link rel='stylesheet' href='/google_maps_by_pete/maps.css'>
- Paste this partial to your _form.html.erb file: /app/views/places/_form.html.erb
<%= render 'shared/google_maps_by_pete', api_key: 'your_google_api_key', height: '500px', center_map_on: {lat: 25.761681, lng: -80.191788}, model: place%>
- Allow parameters (lat and lng) in your controller: /app/controllers/places_controller.rb
def place_params
params.require(:place).permit(:name, :description, :lat, :lng)
end
Video Tutorial
Watch this video to see how it works
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/peterconsuegra/google_maps_by_pete. 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 GoogleMapsByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.