Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Top 10-15 rails view helpers I should learn first?

I am learning rails 3, and want to know which view helpers I should master first?

i.e. which ones are used the most often?

1. form_for
2. ??
..
..
like image 909
Blankman Avatar asked Feb 15 '11 20:02

Blankman


People also ask

When should you use helpers Rails?

Best Practices for Writing Rails View HelpersWhenever you have logic that produces bits of HTML. Usually, this falls into one of two categories, one is string formatting & the other is conditional page elements.

What are Rails helpers used for?

Basically helpers in Rails are used to extract complex logic out of the view so that you can organize your code better. I've seen two benefits for using helpers in my experience so far: Extract some complexity out of the view. Make view logic easier to test.

Where are custom view helpers Rails?

Custom helpers for your application should be located in the app/helpers directory.

How do you use helpers in Ruby on Rails?

A Helper method is used to perform a particular repetitive task common across multiple classes. This keeps us from repeating the same piece of code in different classes again and again. And then in the view code, you call the helper method and pass it to the user as an argument.


2 Answers

I think these are generally considered quite important and they should give you a great start to understanding code and creating forms and pages of your own.

  1. form_for
  2. link_to
  3. image_tag
  4. stylesheet_link_tag
  5. javascript_include_tag
  6. content_for
  7. label_tag
  8. text_field_tag
  9. submit_tag
  10. select_tag
  11. options_for_select
  12. check_box_tag
  13. radio_button_tag
  14. form_tag
  15. collection_select

Some other useful ones as well:

  1. auto_link
  2. pluralize
  3. simple_format

I would also work on understanding the difference between simply calling select_tag and calling f.select, where f is a form_for variable. These are generally the two different ways in which you create forms with helpers in Rails.

I would also make sure you understand the html_safe, raw and h functions for strings and displaying text on your page.

like image 102
Pan Thomakos Avatar answered Sep 20 '22 04:09

Pan Thomakos


If you haven't already, read through the tutorial here:

http://edgeguides.rubyonrails.org/form_helpers.html

like image 43
TK-421 Avatar answered Sep 19 '22 04:09

TK-421