Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Presenting Models with Forms > Creating Helper Methods

Creating Helper Methods

So far, this chapter has shown you how to use a number of the helper methods that come with Rails. You can also create your own helper methods. There are lots of good reasons to do so:

Less repetition

You can come closer to Rails’ DRY (Don’t Repeat Yourself) ideal if you can combine multiple pieces into a single invocation.

More readable code

You can see more obviously which pieces of your code are actually doing the same work when they call the same method, instead of perpetually reinventing the wheel.

More consistency

The same code used in multiple places will rarely stay identical.

Sharing across views

Multiple views within an application can reference the same helper methods.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint