Building ‘Instrumental’ with Rails

Aaaaaand done.

Just finished my musical instrument rental service. There’s no CSS, and I’m a bit self-conscious about that; I have a friend also doing the learn course who makes his apps look flippin beautiful each time. Ah well, though. I’m happy with what I put together. It’s nice getting some real experience working with Devise, in particular. It feels like I’ve been working with Rails so long, it’s surprises me that this is my first Rails app.

I’m starting to realize that the hardest thing about programming can sometimes be all the different ways there are to do something. I’ve heard that Python only lets programmers do things one way, and I have to admit that the idea makes me feel a bit jealous. The issue isn’t only that there are fifty different ways to do Thing A and fifty different ways to do thing B, and having to make that choice, but that only certain ways to do Thing A are compatible with certain ways to do Thing B. I think if there’s a part of programming that intimidates me the most, that’s it. For example, I spent a lot of time in this app reviewing nested forms and custom attribute writers and understanding that writing custom nested form fields like this:

    <input type=”text” name=”user[addresses_attributes][ ][street_1]”>

<input type=”text” name=”user[addresses_attributes][ ][street_2]”>

….will result in an array of hashes in the params.

HOWEVER!

Most people don’t do this. Most people use the fields_for form helper, which uses the number of instances of address in the preceding #new method to generate THIS!

     <input type=”text” name=”user[addresses_attributes][1][street_1]”>

<input type=”text” name=”user[addresses_attributes][1][street_2]”>

    <input type=”text” name=”user[addresses_attributes][2][street_1]”>

<input type=”text” name=”user[addresses_attributes][2][street_2]”>

The difference? THIS code, instead of producing an array of hashes in the params, results in a hash of hashes which kind of ACTS like an array because the keys are numbers, but is NOT an array. So when you try to iterate through the addresses later in your custom writer, you have to make sure to include a param for the index as well or things break.

Whew.

So that’s probably my biggest technical takeaway from the project. Also, I totally get Devise now. It’s pretty nice not having to deal with all of that security stuff, even if it gets annoying sometimes not to have access to my users controller. Interestingly enough, I kind of got used to not being able to work with users in the way I used to. I know there are ways to duplicate the controller and work with it anyway, but I’ll leave that can of worms on the shelf for now.

I also got a lot out of the project in terms of learning about task management and organization. There’s so much to do that I really have to have a system figured out, and near the end there I kind of became my own little SCRUM team.

So I’m sure I’ll look back on this project in a year and cringe like I never have before, but I’m pretty happy with this right now and everything I learned while doing it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s