March 30th 2020
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.
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.
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.
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.
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.
gem 'randumb'
in Gemfile, running bundle after which we can use order_by_rand on Active record to randomize results order.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 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”.
<%= render partial: "product" , collection: @products , as: :item %> |
<%= render @ products %> |