From the course: Ruby on Rails 5 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Text helpers - Ruby on Rails Tutorial
From the course: Ruby on Rails 5 Essential Training
Text helpers
- Rails provides many Helper methods to make common tasks in our View templates easier. In this movie, we'll take a quick look at some of the most useful Text Helpers. We're going to be looking at word_wrap, simple_format, truncate, and pluralize. These should give you a feel for how Text Helpers work, and how they can help you. Word_wrap is used when you have long sections of text. That might just be text that you have stored in a variable, or, more likely, it's probably text that you pulled back from the database. We want to wrap that text so that it's no longer than a certain line length. So we use word_wrap. We provide the text as the first argument, and then, if we want we can specify the line width that we want. It's going to be 80 by default. You can see here I've got it set to 30. What word_wrap does then is it breaks each line on the first white space character which does not exceed the line width. It does not break up words. So you can see here, each of the words is intact…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.