IT Blog, Web Development,

Ride Those Rails With Style!

2 m read
QArea Expert
QArea Expert Marketing Manager
September 14, 2015
Share on
Reading Time: 2 minutes

Imagine a world where you can easily deflect any challenge your RoR project throws at you. That perfect world can indeed become reality once you put your mind to it. Ruby on rails development includes numerous simple tricks and hacks that can dramatically assist developers. The only trouble is that useful things are often too tiny to be spotted at the right moment. That is exactly why you require to know all of them from the start. And, preferably, even before that.

I couldn’t be more honest if I told you that I wish I’ve known the following tips at my time. They would have saved me a lot of time, effort and headache. And to make the long story short let’s dive directly into some RoR greatness:

  • Custom apps that are rails-based often generate content on their own. And they tend to insert HTML as any CMS like WordPress, etc. All of that sounds lovely and magical until a certain point when you will require to truncate some content to get a clear display on the search results page or anything of the same sort. Hear those bells? They say you’re in trouble! Sure you could use a simple .html_safe but all you will get as a result is a divthat will never be closed. You truncated it, did you not? And now you sit there and look at a nightmare that’s going on live and the worst part is – you’re the one who’s to fix the mess. BTW the fix is quite simple, just consider the following: <%=truncate((sanitize blog.body,:tags=>%w(img)),:length=>600)%> and you will be able to include and exclude precise HTML tags of your own will and choice.
  • URL structure changes can be done the hard way or our way despite all possible reasons you have to make the change in the first place. As you probably know changing URL names is a hell of a deal and involves more pain than your body placed in a tub full of fire ants. So let’s imagine you have an URL like /gallery/title-slugand you must change it into /portfolio/title-slug. You can change the model name in any way you were going to do it, or you can use the following in your routes: resources :portfolio, :controller => ’gallery’ and march onward to victory. One more friendly advice – use the link_to URL method in your project. Why? because that’s how you fix all from just one place. In other cases you will probably be forced to manually find and change each link which is time-consuming, yet still less troublesome than the alternatives. As a pleasant addition – if you forget one URL somewhere nothing will get broken.
  • Here’s one more nice tip that can assist you with creation of a real-deal hash from a particular list of values via Hash[…].

Example:
Hash[‘key1’, ‘value1’, ‘key2’, ‘value2’]
# => {“key1”=>”value1”, “key2”=>”value2”}

  • Watch out for latest versions of Rails. They often come with bugs and glitches version 1.9.3 had an issue with taps/heroku/ruby which lead to numerous Data Base-related trouble and the quickest fix lied in degrading to version 1.9.2. New stuff may seem cool and all but you should really take your time before diving heads-in into new glory, otherwise you might get yourselves a serious bump on your head.

Do you have any other cool RoR tricks up your sleeves? Please share them through the comments!

Categories

Recent Posts

  • From Gaming Videos to Redefining Instant Messaging: Quinn Hu's Long Path to Serial Entrepreneurship

    Read more
  • 7 Reasons to Truly Love Microservices

    Read more
  • The Best Languages for Microservices

    Read more
  • QArea's Year: Summing Up 2018

    Read more
  • What's New in Golang 1.11: Release Notes Overview

    Read more
  • The Most In-Demand Backend Programming Languages of 2019

    Read more
  • Best Frontend Programming Languages to Create Beautiful and Fast Interfaces

    Read more
  • Capability Maturity Model Integration – QArea's big journey

    Read more
  • QArea is a Unique Services Provider in 2019 CEE Awards

    Read more
  • Ultimate Development Trends in 2018 to Reward Your Business in 2019

    Read more
  • Why You Should Write Your Next Microservice Using Golang

    Read more
  • Why You Should Try Golang Development Capabilities With QArea

    Read more
  • Top 7 Software Development Outsourcing Companies For Your Business Prosperous Growth

    Read more
  • CMMI Appraisal and Its Impact on QArea’s Development

    Read more
  • Software Prototyping VS Minimum Viable Product: what works for you

    Read more
  • Refactor or not refactor? Everything there is to know about refactoring

    Read more
  • 7 Stages of Software Development Cycle

    Read more
  • What is DevOps, and why is it crucial for microservices-based development

    Read more
  • Moving to Microservices: Top Products & Services

    Read more
  • QArea becomes a finalist of the European software testing awards 2018

    Read more

Subscribe

Yes

Share on
Privacy Preference Center