5 things I wish I knew long before I started programming in Rails

January 22nd 2016

Every beginning is hard. Fortunately there are some bumps on the road that are easy to remove. Whether you're just starting with rails or you've hit a wall and want to quit try considering these insights to help you overcome a rough start.

 

Trying Rails on windows for the first time can discourage you

Few years ago I had a short encounter with rails. I had some extra time on my hands and wanted to try this technology that was so loudly praised in web development circles. One thing that set me back was that I was then running a Win7 machine. Even though it seemed like a bad idea just from the look of the tutorials available on the internet I wanted to proceed on Windows. Well after long hours of setting up the environment and frustrating myself I managed to scaffold an app, test few things and realize it is cool indeed. Trying to tinker around a bit more I managed to make some mistakes which led to some strange errors and I concluded that it is ok but probably going to be buggy, time consuming and nerve wrecking so I chose to abandon this quest. Boy was I wrong, but I only discovered that years later.

Suggestion: If you don’t own a Mac you could try running a Linux distribution of your choice. The whole process of setting up is way more convenient with Terminal. If that is not something you can do try cloud development environment Cloud9 http://c9.io/ which gets you started from your browser. With C9 you have text editor, filesystem navigator and a command-line terminal which is more than enough to get you up and running in no time.

 

Your environment: colleagues, technology and projects are as crucial as your personal motivation in making a transition. Rails makes transitions easier.

Crossing over from one technology to another can be exciting but also very stressful. Some practices you used to do and you base your style of getting things done may not be suitable for other environment. Every transition is turbulent but having the right people around you can help a lot. Rails community seems to be one of the chillest I’ve encountered. That helps a lot. But the technology itself can help you with transition too. The gratification is strong with Rails. It’s not uncommon for a beginner in Rails to fix a problem in such an elegant way you got to stop and admire it for a moment. This creates that sweet feeling of progress which I like so much being a developer, and the best thing is that it happens really often. That really helps fuel your desire to improve and increases engagement with the projects you do. And motivated developer is a good one in my book.

Suggestion: Your first touch with Rails community can be with the work colleagues. Having a common goal like a project with more experienced developers is an awesome chance for gaining knowlege. If there is no project to work on try creating fun open source project to work together with someone. Another thing to check is meetups near you. I was lucky to have SARMA http://www.meetup.com/Sarma-Sarajevo-Ruby-Meetup/ near me where people exchange knowlege and are very warm with newcomers.

 

Rails official guides are actually way too good to pass

Rails guides (http://guides.rubyonrails.org/) is one resource I keep coming back. First time I opened the guides I went through the Getting Started with Rails guide underestimating the power of the other guides. Not long after I realized this mistake. Simply googling a lot of questions I had would bring me back to the guides. The guides may be too detailed for when you need a simple answer but using them in a right way always produces solid knowledge about the issue you had.

Suggestion: Do more of the rails guides. There are a lot of great resources on the web for learning Rails. The ones I can warmly suggest are https://www.railstutorial.org/book and official guides.

 

Knowing right gems is very important

In a lot of situations when I had a feature that would require a lot of monotonous time and effort to do from the scratch the right gem would jump in and save the day. Over and over again when discussing the task I had in front of me, a more experienced colleague would tell me about a gem that I should look into. With time I too started keeping track of these gems which are in many cases life-savers. The gems you use and the way you use them seem to be the essential part of being a rails developer.

Suggestions: The gems which saved me a lot of time range from 'carrierwave' which makes uploading files from Ruby applications silly easy to 'randumb' which helps you retrieve random records from active record and 'will_paginate' which helps making pagination.
For example: 'randumb' works by inserting gem 'randumb' in Gemfile, running bundle after which we can use order_by_rand on Active record to randomize results order.
Will_paginate works in similar way. Add gem 'will_paginate' in Gemfile, run bundle and after that you use Post.paginate(:page => params[:page], :per_page => 30) to paginate results and add<%= will_paginate @posts %>to the view where you want your pagination to be and thats it. These gems vary from very simple to more complex but your can customize them and tailor them to your needs. You may not see some of them as a big improvement but they add up and save you a lot of time.

 

Rails philosophy is not just a philosophy.

Rails starting guide says in the first chapter  “The Rails philosophy includes two major guiding principles: Don't Repeat Yourself: … Convention Over Configuration: …” and it really does. I’ve heard a lot of statements from a lot of frameworks including these ones but rarely you find a framework which guides you towards respecting those philosophies as Rails does. Its too easy to stray away from the right path (especially when in hurry) but Rails keeps you on the track over and over. Its so much easier when you know the conventions and makes you that much more efficient in providing quick elegant solutions that you can not simply stray away. Once again Rails does not whip you into submission with its strict practices but lures you in with your code being cleaner, simpler and much easier to write by following the “Rails way”.

Suggestions: Learn the conventions and respect them wherever you can. Having a line 
<%= render partial: "product", collection: @products, as: :item %>
can be shortened to just as much as 
<%= render @products %>
if your collection is @products, your partial is named _product.html.erb and you use the collection inside the partial for example as <%= article.title %>. It may not seem as a big improvemenet but it does streamline the job and it looks way cleaner.

Popular posts