Code Monkey home page Code Monkey logo

autocomplete_locations's Introduction

AutocompleteLocations

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/autocomplete_locations. To experiment with that code, run bin/console for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'autocomplete_locations', github: 'https://github.com/elitmus/autocomplete_locations', branch: 'master'

And then execute:

$ bundle

Mount it in routes.rb:

mount AutocompleteLocations::Engine => "/"

Load javascript file in application.js:

//= require autocomplete_locations/location_autocomplete

Run rake task:

$ rake location_fixes:init_autocomplete_locations_module
$ rake db:migrate
$ rake location_fixes:update_locations

Dependencies

Add these lines if they don't exist

In your Gemfile

gem 'jquery-rails'
gem 'jquery-ui-rails'

In your application.js

//= require jquery
//= require jquery-ui

And in application.css

 *= require jquery-ui

Usage

To add location as a reference to your table:

$ rake location_fixes:add_location_to_table table='TableName'

If the table is already populated with some city name:

$ rake location_fixes:update_location_to_model model='ModelName' column='city_column_name'

For a model having autocomplete_location_id, search query can be concatenated for finding cities with same city_id:

ModelName.at_city_id(autocomplete_location_id)

But before saving or searching using the city_id obtained from the form, validate it's location first and then fetch id again using:

ModelName.city_id(location_column_value) #use this autocomplete_location_id

Enabling javascript on an autocomplete_field:

$("#city_input_field_id").locationAutocomplete(data, "#hidden_city_id_field", "#city_input_field_id", "#state_field_id option");

Testing

In your factories.rb, require autocomplete_location gem's factories.

require 'autocomplete_locations/factories'

For each tables with autocomplete_location_id as a foreign key, add this line:

autocomplete_location_id { create(:autocomplete_locations).id }

Development

After checking out the repo, run bin/setup to install dependencies.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/elitmus/autocomplete_locations.

Problems: What if same city name exist in different states%

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.