Javascript Project

Flipping Tables



Most blog posts are about how to get things done. How you solved a problem or how you discovered a solution to a problem.  This one is going to be different.  This is going to be about an inherent problem I discovered while working with Javascript that seems to not have a real solution.
Part of the project requirements was to use a Rails API as our back end.  In the past, while working with rails, I had become a fan of a particular datatype for PostgreSQL (and a few other databases) called hstore.  Hstore allowed for storing key value pairs in a single column in a database.

For example:  You can store all parts of an address (street, city, state, etc) in a single column and call them later, individually, just as if it was stored in separate columns.  When creating a form in Rails for submitting data to that column you would need to use a slightly different approach.  Instead of using Form-For you would use Field_for and Openstruct to create a form that had multiple lines of input but all pointed to the same column in the database being entered as key value pairs.

So as I started up this project I worked on the API first.  I had need to store addresses and hstore being am excellent solution for this, I implemented it.  Fast forward a few days and I run into a problem.  JavaScript uses pure html when rendering.  Which meant I didn't have access to fields_for and Openstruct.

I spent the entire day looking for a solution.  There where a couple of hackish ways to get JS to read hstore data and parse it but nothing really on how to get it to submit data in that same key value pair structure. I'm not saying there is no solution, but I am saying there is no easy to find solution.

This calls for more research.  Can JS render erb files?  Can I write an erb file in the back end and just have JS call it some how?

If none of these are true I feel JS is missing a useful and powerful tool from it's tool set.

Comments

Popular posts from this blog

Introducing Dir

Flatiron Final Feelings

Teaching to Learn