Book Image

Rails 4 Application Development HOTSHOT

By : Saurabh Bhatia
Book Image

Rails 4 Application Development HOTSHOT

By: Saurabh Bhatia

Overview of this book

<p>Rails is a rapidly moving, open source, web development framework, and keeping up to speed with it is a big task. You might have already built applications using it, but there have been significant changes in the syntax and semantic of the Rails framework in the latest upgrade.</p> <p>Rails 4 Application Development Hotshot shows you how to build the most popular types of applications using Rails 4, and highlights new ways to do things. The book also closely follows lots of the best practices, gems, and popular solutions already known to the community, and tracks the changes in these. This book brings new ideas to refactor and restructure code to make it perform better in production, and enables you to write production-ready code.</p>
Table of Contents (17 chapters)
Rails 4 Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating points of interest – filter users based on their location


Grouping similar information on the map according to a specific criteria is called points of interest. This is a term used for markers or points on the maps that can be categorized or grouped together. We will use locations as the points of interest in our application. We will call all the locations in our system and search the friends according to it. We will use the geocoder API to do this.

Engage thrusters

We will create location-based filters for our users in this task:

  1. The geocoder gem has a method called near, which takes the location string as the parameter and runs a spatial query on the database:

    1.9.3p327 :001 > user = User.first
    1.9.3p327 :002 > user.friends.near("NY")
    
  2. We got six results when we searched for the term NY:

    1.9.3p327 :003 > user.friends.near("NY").length
      Friend Load (1.6ms)  SELECT friends.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((40.7143528 - friends.latitude) * PI() / 180 / 2), 2) +...