ActionView has built in helpers that are used in the view in rails. http://api.rubyonrails.org/classes/ActionView/Helpers.html
Below are common ActionView Helpers and some examples of what they do:
To demonstrate and visualize ActionView features I have create the following
project which is posted online at: https://github.com/natashashannon/ActionView. Code for this project
is located in the README.md file.
In application.html.erb file there are the following ActionView items:
tag helpers that generate the html that links the .erb to the assets including
- The csrf_meta_tags is a helper that helps to prevent Cross-Site
Request Forgery http://api.rubyonrails.org/classes/ActionView/Helpers/CsrfHelper.html
- <%= yield %> Is an ActionView tool that creates
“3.2 Understanding yield. Within the context of a layout,
yield identifies a section where content from the view should be inserted. The
simplest way to use this is to have a single yield, into which the entire
contents of the view currently being rendered is inserted” http://guides.rubyonrails.org/layouts_and_rendering.html#understanding-yield
If the <%= yield %> instead looked like
<%= yield %>
<%= render 'form' %> Render creates a
new template and in this case a form.
- <%= form_tag(dogs_path, :method = "get", id: "search-form")
form_tag is for a form that posts, whereas form_for is a form helper that
allows a user to create or update
- <%= text_field_tag :search, params[:search],
placeholder: "Search Users" %>
text_field_tag is a form helper that creates a text field.
- <%= submit_tag "Search", :name = nil %> is a form helper
that creates a submit button
- <%= f.date_select(:expiration_date,:start_year = 2014,
end_year: 2030) %>
date_select is a date helper and start and end year are some of the options
that can be used with this helper.
September 13, 2014, Natasha Crowley