Rails magic

My most important take-aways from this week full of Rails magic:

  • Do not touch the link tags in application.html.erb.
  • Do not compile your code locally.
  • Do not mess with the sprockets. Ever.

Phew! OK. I will follow these warnings.

Furthermore I can report that Michael’s much used term of something being “borked” (usually a database) has now entered my active vocabulary and used it this morning in the context of our boiler. (Luckily we managed to un-bork it and I didn’t have to go to the gym to shower after all.)

So far, I have to say that Rails is being kind to me. Things are working and if they’re not, I understand how to fix them. But maybe this also has to do with the instructors being kind to us – I feel like we’re not moving at lightning speed anymore like in the first couple of weeks. We seem to be taking a bit more time to repeat important things. The homework projects on Wednesday and Thursday were fine too. In contrast to previous weeks where I sometimes felt like I was trying to build a spaceship, I now feel more like I am applying something that we learnt during the day. Which is probably the actual purpose of the homework. I’m not sure if this is the instructors’ intention or just my personal perception. Maybe I’m just more used to learning now? Maybe I know how and when to ask for help better than in the beginning? Comments are welcome.

Continuing with our Rails basics lessons, we learnt some tips and tricks for debugging our apps, how to create partials and what the deal with the Rails models and the asset pipeline is.

On Thursday we were introduced to associations in Rails which initially went so far over my head that I thought I would need to get one of these butterfly catching nets to collect it again. But we are practising the different associations one by one now and it is kind of making sense.

We started with the ‘one-to-many’ association (using our very basic cookbook app as an example: a recipe can only be in one category but a category can have many recipes).

On Friday afternoon Jarkyn and Alex (our teaching assistants) demonstrated a ‘many-to-many’ association using the example of a student and beer app: one student can drink several different types of beers and each type of beer can be drunk but several different students. Many-to-many. It was a bit hard to follow when all that everybody could think about was finally going to the pub and people had been putting images of beers into our HipChat group since about 11am in the morning. But I tried to cut through the thirst and really pay attention as we needed this for our weekend homework (another recipe app!).

I have to say, so far it paid off and I managed to create the ingredients object (a recipe can have many ingredients and one ingredient can be used in many recipes) and run the database migrations. So far, so good!

I hope I haven’t jinxed my luck now and will need to turn into a crying wreck over my laptop when I try to actually display the ingredients on a page and create the functionality to add new ingredients to recipes.

Ah, one more thing: on Friday we also learnt how to push our apps to Heroku, a free cloud hosting service. So finally I can put stuff that I create on the internet! Very exciting.

Fingers crossed for my homework – hopefully the internet will get to see those ingredients in my app of German recipes…

Advertisements

Rails is here!

It’s Wednesday morning and once again I’m on my way to hipster central, i.e. the place just off Bricklane where General Assembly is teaching WDI.

Yesterday was Rails day and after the homework review we installed Rails onto our computers. How exciting!

Michael promptly went on to show us how to create yesterday’s recipes app on Rails. Creating the app in Sinatra yesterday took us the whole day including homework. With Rails it took us about 15 minutes.

Mind = blown.

I felt like I started walking to China on crutches two weeks ago and now someone told me that there is such a thing as a car and I just need to sit in it and drive.

Over the course of the day we learnt a bit more about Rails: the routing (REST and all that), some helpers for writing HTML that actually just confused me more than anything else (I just about know how to create forms in HTML so now you want to take that away from me and make me use Rails helpers instead…?) and we went through all the mysterious folders and files that Rails creates automatically when it loads up a new project.

Going back to the China analogy: if Rails is like driving a car – it actually took me quite a few expensive driving lessons when I was 17 to get my driving license. And people say you only really start learning how to drive after you have your license. So I guess that’s the same with Rails. Michael described it as eating an elephant bit by bit over the next two weeks. Yeah, kind of yucky but you get the gist.

The homework last night was to put the MTA stations calculator from week 1 onto Rails. Why do all these projects come back to haunt me? Luckily the basic bits of the homework turned out to be relatively ok and I got them done quite quickly. I helped some of my classmates with it and then went home to have dinner and tackle the optional bits (why don’t I create a drop down field here? Yes! Why not? That should be easy, right?! Ooohhh no. Not with the form helpers).

Then I did some CSS and called it a day at about 10.30pm or so.

Ups and downs…

Today is probably more of a ‘down’. After I was so pleased with myself for understanding the weekend homework, today was another one of those depressing days where I’m not sure what’s going on.

We basically created another app with the create, read, update and delete functions but this time we extracted as much code as possible into an O/RM (object-relational mapping) file, so that the SQL commands wouldn’t get mixed in with our other code. Makes sense and I’m all for tidying up but somehow this really confused me.

It was a recipe app that we created, using two classes: the recipe class and the category class. For our homework we had to add some additional functionality but none of the things I tried worked. I kept going back and forth and tried this and that and yet always got the same errors in Ruby.

I tried using Pry-Byebug to debug it. I tried to figure out individual functions directly in irb. And when I thought I had it, it still didn’t work once I put it in one of the many erb and rb and what not files. Argh! Nightmare.

Apparently we’re starting with Rails tomorrow, which is supposed to automate a lot of stuff. Maybe it will automate the things that I couldn’t do today? Pretty please, Rails??!