natasha shannon crowley

work samples


ActionView, Ruby on Rails

What is ActionView?

ActionView Helpers

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.

Project Files

 /supplies/app/views/layouts/application.html.erb

In application.html.erb file there are the following ActionView items:

  1. The stylesheet_link_tag and javascript_include_tag are asset tag helpers that generate the html that links the .erb to the assets including stylesheets and javascripts.
  2. The csrf_meta_tags is a helper that helps to prevent Cross-Site Request Forgery http://api.rubyonrails.org/classes/ActionView/Helpers/CsrfHelper.html
  3. <%= yield %> Is an ActionView tool that creates the layout
    “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
    http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html If the <%= yield %>  instead looked like <%= yield %>  

/supplies/app/views/layouts/new.html.erb

  1. <%= render 'form' %> Render creates a new template and in this case a form. http://guides.rubyonrails.org/layouts_and_rendering.html

/supplies/app/views/layouts/index.html.erb

  1. <%= form_tag(dogs_path, :method = "get", id: "search-form") do %>
    form_tag is for  a form that posts, whereas form_for is a form helper that allows a user to create or update
  2.  <%= text_field_tag :search, params[:search], placeholder: "Search Users" %>
    text_field_tag is a form helper that creates a text field.
  3. <%= submit_tag "Search", :name = nil %> is a form helper that creates a submit button

/supplies/app/views/foods/_form.html.erb file

  1. <%= 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

https://github.com/natashashannon/ActionView.