Hi Al,

You are probably right, but that is what would have taken me days or weeks to figure out, implement and debug ;-) .

Don


On 08/18/2013 07:33 PM, Albert Chou wrote:
Not to be a wet blanket, but wouldn't gon = Struct.new(:listings, :neighborhoods, :names, :nbh_id).new followed by populating gon and then calling gon.to_json have worked?

Al


On Sun, Aug 18, 2013 at 8:15 AM, Donald Ziesig <[email protected] <mailto:[email protected]>> wrote:

    Hi All!

    This is not directly related to Hobo, but it was so cool I just
    had to pass it on.

    I needed to transfer large amounts of data from multiple models to
    the view's javascript.  I was anticipating spending days, if not
    weeks, generating the necessary code.  One very lucky google
    search later, I found the "gon" gem.  This gem of a gem (I
    couldn't resist) takes data from ruby (e.g., array of arrays of
    arrays, hashes containing arrays) and translates it into a
    <script>....</script> containing the data in javascript code.

    In less than 20 minutes I had geographic data covering all of
    central Florida and selected realestate listings moved from my db
    tables to the view and processed by javascript code for display by
    google maps.

    Just add

    gem "gon" # Converts ruby objects to javascript objects in view !!!!!

    to your Gemfile (followed by bundle install).

    In the appropriate controller, setup the data then add:

        gon.listings = listings                            # An array
    of hashes containing arrays of hashes
        gon.neighborhoods = neighborhoods  # An array of arrays of arrays
        gon.names = names                            # An array of strings
        gon.nbh_id = nbh_id                             # An array of
    integers.

        hobo_show                                            # Plain
    old Hobo

    Add to the view(s):

         <%= include_gon %> <!-- might want to covert this to a dryml
    tag but its so simple... -->


    Finally, use the data in javascript files:

        poly = new google.maps.Polygon(
        {
          name: gon.names[i],
          nbh_id: gon.nbh_id[i],
          strokeColor: "#000000",
          strokeOpacity: 0.8,
          strokeWeight: 1,
          fillColor: "#000000",
          fillOpacity: 0.0,
          paths: gon.neighborhoods[i]
        })

    If this is useful to anyone, let me know.  With sufficient
    interest I might even add it as a recipe ;)

    Don Ziesig

-- You received this message because you are subscribed to the Google
    Groups "Hobo Users" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to [email protected]
    <mailto:hobousers%[email protected]>.
    To post to this group, send email to [email protected]
    <mailto:[email protected]>.
    Visit this group at http://groups.google.com/group/hobousers.
    For more options, visit https://groups.google.com/groups/opt_out.




--
Finding a solution to a problem requires different thinking from that which created the problem. - paraphrasing Albert Einstein
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to