Problem Solving Rails and React

I’ve decided to add React to a Rails app I built.  Right now I am trying to create a select box in a form.  The form creates new Transactions.  Each Transaction belongs_to one Program and one Account.

Currently I have the Transactions showing up, along with a form and delete actions.  But I am having some trouble.

The first bit of trouble is that I’m using CoffeeScript, which is new to me.  React uses JSX and vanilla JavaScript.  So translating to CoffeScript is confusing, although not impossible.

The next layer of trouble is how to create a select box in React.  React has no form_for or options_for_select helpers.   I have figured out how to create a select box, but I need it to be populated by the database table Programs.

The third layer of difficulty is how to deal with associations.  I can’t type Transaction.program.name in the view like I can in Rails, and I can’t use a raw SQL query in the JavaScript.

To help wrap my head around the problem, I decided to follow Justin Weiss’s fabulous advice, and build a mini-app.  This simplified the problem for me, by taking it down to the simplest level that I was having trouble with – how to access associations in a rails app, using React.  Thanks to this excellent tutorial, and with a bit of muddling around, I’ve figured out how to access associations.  Now I have to figure out how to put this into a select box with coffeescript.

Leave a Reply

Your email address will not be published. Required fields are marked *