trying to build simple web app with Google Maps API - ruby-on-rails

I'm trying to build a simple web app using the Google Map API. I haven't decided if I want to use Rails or Django yet. I've been looking for some tutorials, but none have given me really what I'm looking for. Understand, I'm a newbie when it comes to both Rails and Django.
What I want to do is like this:
http://durasupreme.com/dealer-locator
Where you type in a zip code and it returns a map with pins for the locations on a map. I already have the database information, I'm just wondering what the best way to do this. I feel like I have the idea, I know the tools I need to use, but I don't know how to put it all together.
Any help or links to resources would be greatly appreciated.
D

Here are a few useful links if you decide to go for Rails:
Geocoder
Railscast about Geocoder
Google Maps for Rails

What you are trying to do doesn't have much to do with Django or Rails. It will be mostly javascript. Here's a simple implementation outline:
Follow the tutorials to get started on google maps api on a static local html file.
In javascript write a map_init and add_marker helper functions.
When confident, add the link, div, and script tags you wrote to your template.
Have your view/controller method get a list of objects from the db.
Pass them to the template
In the template do a for loop over the object list.
inside the loop use the appropriate obj attributes to feed the add_marker helper function.

Related

How to connect Rails app to a website's API?

I know I'm going to get downvotes for even asking but I honestly have no clue how to do this and any assistance would be appreciated as I have never done this.
I have a client that migrated their blog to HubSpot and would like to have their blog posts displayed on their website. So how do I connect to HubSpot's API to display the blog in their website that I have in a Rails app?
Do I create MVC just for Blog API? Where do I put the URL to connect to?
If you want to connect to an other API the best way to do this is to create service objects. These are plain old Ruby objects (aka PORO) that represent the API as a Ruby object. You are free to use any location you want, but I would stick them in lib/services or app/services. If the provided API uses the Rails (REST) standards than you might be able to use ActiveResource.
You could also look for gems that provide these service objects. A quick RubyGem search finds multiple (unofficial) gems. From witch hubspot-ruby seems the most used and active.
If the gems don't do what you want you could look through the code to find some inspiration and create you own objects. Another option is to fork a project and add the functionality you want.
Here is a link to answer the broader question you're asking: What is the proper "Rails Way" to consume a RESTful web service on another domain?

Best method for simple GET based Ruby on Rails app

Im trying to understand the best method for creating a basic Rails app that is only interfaced with via GET values in the url. Im attempting to understand how to go about starting to write logic for this as well as generally where i would want to start coding. Would this main interface code be considered a helper? or should i migrate the code to the model?
An example of how i'd like to use this app is something like the following.
http://www.railsapp.com/?order_number=123&print_label=true
With this example url i hope to grab the order_number get some information from it, determine if print_label is true/false and output something to the user.
Im not looking for someone to write it all for me, i'm simply needing some guidance on the best structure on writing a rails app that is only interfaced with via a URL as well as the easiest method for gather GET values.
Between the 3 comments on the first post i am going to looking into Restful routing and by that gather my params to interact with them.

Using AngularJS in Ruby on Rails app

I have a existing project in Ruby on Rails.
What is the best way to use AngularJS in Ruby on Rails app?
I want to use AngularJs for only specified modules, not for create SPA. This is good way?
What I have seen colleagues do in order to achieve this sort of integration with an existing rails app is:
Include angular.js and relevant dependencies in the specific app pages that are to be 'angularized'
Interpolate whatever data is needed to bootstrap the angular controller into the html template which contains the angular app. This might include data about the resource being operated on. I've seen this done by rendering a RABL template inside of a haml/erb template.
Using that interpolated data, call whatever API methods you need to get additional data on the fly. This is usually just a matter of implementing json handlers for routes you've already created.
I can't say whether this is best practice, but its an easy way to get started fast.
Best of luck, angular is a very enjoyable tool to work with once you get used to it.

Searching WordPress blog from Rails app

I have a site-wide custom written search controller for my Rails 3 app and would like to include results from the site's WordPress blog. What is the best way for me to perform a keyword search on posts from within my Rails app?
If you share database then just use SQL query on it. This solution gives you speed of direct db query but you’ll need to construct that query properly in order to get all relevant data.
If you don't have access to the WP database from your Rails app then the best way will be to use curl, httparty, RestClient or any other file retrieval library.
To do that, create Wordpress page with custom template which will output search results in a format which is best for you to parse in Rails app (json, xml, csv, urlencoded, whatever).
Then request that WP page from your Ruby app using curl/RestClient/httparty…
This solution gives you the power of WP template tags and functions to get the results.
Also instead of creating custom template from scratch you can just simply copy and tweak search.php from core template to provide the results in a format required by your Rails app.
With this solution you are lacking the speed of direct access to db because all search result will have to be transferred through http pipe and you have to process the data twice (encode to the proper format in WP and decode in Rails app).
Interesting problem. I think I would approach it like this:
Use RSS as the text transport from the blog to your rails app. This allows the flexibility to add more blogs in the future, change your blog engine, database host, etc. It also protects you from Wordpress code updates. Given the security history of Wordpress, I like to host them in a protected sandbox anyway. RSS is the native language for blogs, so it seems a natural fit for this kind of content integration.
Use the feedzirra gem to import RSS entries into a rails model.
Use Elasticsearch and tire for fuzzy text searching across both your rails app and your blog entries. See this Railscast for details.
Option 1. is to use search engine for both sites, like elasticsearch, solr etc. So you populate the index from rails and wordpress.
Option 2. You write script, that reads periodically your wordpress RSS and saves data in your rails app.
At the end you should avoid to search from different sources, you should gather the data into one place and then search.
You don't have to stuck with wordpress. You can use Google search APIs. Web search api has been deprecated but still working. Its replacement is Custom Search API. You may need to pay if you query over the limit.
Alternatively you can leverage other search engine APIs like Bing Search API.
I'd suggest using the Wordpress JSON API and plugging that into your search using solr or something similar. You can index as posts are created and then call the articles via the sam JSON interface.
Use Tire and wp-elasticsearch with ElasticSearch.

Generating Google Maps markers using Ruby

I would like to do a very simple task: add some markers in a Google Map using a list of addresses from an array.
I have been thinking about generating the Google Maps JavaScript API code using ruby (printf) but this does not seem like a very clean and beautiful solution...
I have read about YM4R for Ruby on Rails... my project is pretty simple and I have never worked with Ruby on Rails... I have also never used JQuery... but I am very willing to learn to use this tools :)
What do you think will be the best approach to generating the markers?
Fyi, I've just released a new version of gmaps4rails.
It's based on Rails 3 and uses Google maps API V3:
https://github.com/apneadiving/Google-Maps-for-Rails
YM4R is a good choice. In the end you'll just need a few lines of code to get this done, as outlined in the tutorial. Even given your background, you should be able to follow the examples and get things working.
We also use the Geokit plugin, which is a little more complicated because of the set-up. But if you already have the lat/lon, you're good.

Resources