A product of Danish Design during the Winter of '79...
Here are a few of our fine products:
<% @products.each do |product| %> <%= render :partial => "product", :locals => { :product => product } %> <% end %> <%= render "shared/footer" %><%= post.body %>
<% end %> This example would output the following:Partial Layouts are cool!
<%= post.body %>
<% end %> <% end %> If we're using the same +box+ partial from above, his would produce the same output as the previous example. h3. View Paths TODO... h3. Overview of all the helpers provided by Action View The following is only a brief overview summary of the helpers available in Action View. It's recommended that you review the API Documentation, which covers all of the helpers in more detail, but this should serve as a good starting point. h4. ActiveRecordHelper The Active Record Helper makes it easier to create forms for records kept in instance variables. You may also want to review the "Rails Form helpers guide":form_helpers.html. h5. error_message_on Returns a string containing the error message attached to the method on the object if one exists. error_message_on "post", "title" h5. error_messages_for Returns a string with a DIV containing all of the error messages for the objects located as instance variables by the names given. error_messages_for "post" h5. form Returns a form with inputs for all attributes of the specified Active Record object. For example, let's say we have a +@post+ with attributes named +title+ of type +String+ and +body+ of type +Text+. Calling +form+ would produce a form to creating a new post with inputs for those attributes. form("post") Typically, +form_for+ is used instead of +form+ because it doesn't automatically include all of the model's attributes. h5. input Returns a default input tag for the type of object returned by the method. For example, if +@post+ has an attribute +title+ mapped to a +String+ column that holds "Hello World": input("post", "title") # => h4. AssetTagHelper This module provides methods for generating HTML that links views to assets such as images, JavaScript files, stylesheets, and feeds. By default, Rails links to these assets on the current host in the public folder, but you can direct Rails to link to assets from a dedicated assets server by setting +ActionController::Base.asset_host+ in the application configuration, typically in +config/environments/production.rb+. For example, let's say your asset host is +assets.example.com+: ActionController::Base.asset_host = "assets.example.com" image_tag("rails.png") # =>Welcome! The date and time is <%= Time.now %>
<% end %> The captured variable can then be used anywhere else.Welcome! The date and time is <%= Time.now %>
*app/views/posts/special.html.erb*This is a special page.
<% content_for :special_script do %> <% end %> h4. DateHelper h5. date_select Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute. date_select("post", "published_on") h5. datetime_select Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based attribute. datetime_select("post", "published_on") h5. distance_of_time_in_words Reports the approximate distance in time between two Time or Date objects or integers as seconds. Set +include_seconds+ to true if you want more detailed approximations. distance_of_time_in_words(Time.now, Time.now + 15.seconds) # => less than a minute distance_of_time_in_words(Time.now, Time.now + 15.seconds, true) # => less than 20 seconds h5. select_date Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+ provided. # Generates a date select that defaults to the date provided (six days after today) select_date(Time.today + 6.days) # Generates a date select that defaults to today (no specified date) select_date() h5. select_datetime Returns a set of html select-tags (one for year, month, day, hour, and minute) pre-selected with the +datetime+ provided. # Generates a datetime select that defaults to the datetime provided (four days after today) select_datetime(Time.now + 4.days) # Generates a datetime select that defaults to today (no specified datetime) select_datetime() h5. select_day Returns a select tag with options for each of the days 1 through 31 with the current day selected. # Generates a select field for days that defaults to the day for the date provided select_day(Time.today + 2.days) # Generates a select field for days that defaults to the number given select_day(5) h5. select_hour Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. # Generates a select field for minutes that defaults to the minutes for the time provided select_minute(Time.now + 6.hours) h5. select_minute Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. # Generates a select field for minutes that defaults to the minutes for the time provided. select_minute(Time.now + 6.hours) h5. select_month Returns a select tag with options for each of the months January through December with the current month selected. # Generates a select field for months that defaults to the current month select_month(Date.today) h5. select_second Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. # Generates a select field for seconds that defaults to the seconds for the time provided select_second(Time.now + 16.minutes) h5. select_time Returns a set of html select-tags (one for hour and minute). # Generates a time select that defaults to the time provided select_time(Time.now) h5. select_year Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius can be changed using the +:start_year+ and +:end_year+ keys in the +options+. # Generates a select field for five years on either side of +Date.today+ that defaults to the current year select_year(Date.today) # Generates a select field from 1900 to 2009 that defaults to the current year select_year(Date.today, :start_year => 1900, :end_year => 2009) h5. time_ago_in_words Like +distance_of_time_in_words+, but where +to_time+ is fixed to +Time.now+. time_ago_in_words(3.minutes.from_now) # => 3 minutes h5. time_select Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified time-based attribute. The selects are prepared for multi-parameter assignment to an Active Record object. # Creates a time select tag that, when POSTed, will be stored in the order variable in the submitted attribute time_select("order", "submitted") h4. DebugHelper Returns a +pre+ tag that has object dumped by YAML. This creates a very readable way to inspect an object. my_hash = {'first' => 1, 'second' => 'two', 'third' => [1,2,3]} debug(my_hash)--- first: 1 second: two third: - 1 - 2 - 3h4. FormHelper Form helpers are designed to make working with models much easier compared to using just standard HTML elements by providing a set of methods for creating forms based on your models. This helper generates the HTML for forms, providing a method for each sort of input (e.g., text, password, select, and so on). When the form is submitted (i.e., when the user hits the submit button or form.submit is called via JavaScript), the form inputs will be bundled into the params object and passed back to the controller. There are two types of form helpers: those that specifically work with model attributes and those that don't. This helper deals with those that work with model attributes; to see an example of form helpers that don‘t work with model attributes, check the ActionView::Helpers::FormTagHelper documentation. The core method of this helper, form_for, gives you the ability to create a form for a model instance; for example, let's say that you have a model Person and want to create a new instance of it: # Note: a @person variable will have been created in the controller (e.g. @person = Person.new) <%= form_for @person, :url => { :action => "create" } do |f| %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= submit_tag 'Create' %> <% end %> The HTML generated for this would be: The params object created when this form is submitted would look like: {"action"=>"create", "controller"=>"persons", "person"=>{"first_name"=>"William", "last_name"=>"Smith"}} The params hash has a nested person value, which can therefore be accessed with params[:person] in the controller. h5. check_box Returns a checkbox tag tailored for accessing a specified attribute. # Let's say that @post.validated? is 1: check_box("post", "validated") # => # h5. fields_for Creates a scope around a specific model object like form_for, but doesn‘t create the form tags themselves. This makes fields_for suitable for specifying additional model objects in the same form: <%= form_for @person, :url => { :action => "update" } do |person_form| %> First name: <%= person_form.text_field :first_name %> Last name : <%= person_form.text_field :last_name %> <%= fields_for @person.permission do |permission_fields| %> Admin? : <%= permission_fields.check_box :admin %> <% end %> <% end %> h5. file_field Returns an file upload input tag tailored for accessing a specified attribute. file_field(:user, :avatar) # => h5. form_for Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields. <%= form_for @post do |f| %> <%= f.label :title, 'Title' %>: <%= f.text_field :title %>
<%= text_field_tag 'name' %>
<% end %> # => h5. file_field_tag Creates a file upload field. If you are using file uploads then you will also need to set the multipart option for the form tag: <%= form_tag { :action => "post" }, { :multipart => true } do %> <%= file_field_tag "file" %> <%= submit_tag %> <% end %> Example output: file_field_tag 'attachment' # => h5. form_tag Starts a form tag that points the action to an url configured with +url_for_options+ just like +ActionController::Base#url_for+. <%= form_tag '/posts' do %>