method

form

Importance_2
v1.1.6 - Show latest stable - 0 notes - Class: ActionView::Helpers::ActiveRecordHelper
form(record_name, options = {}) public

Returns an entire form with input tags and everything for a specified Active Record object. Example (post is a new record that has a title using VARCHAR and a body using TEXT):

  form("post") =>
    <form action='/post/create' method='post'>
      <p>
        <label for="post_title">Title</label><br />
        <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
      </p>
      <p>
        <label for="post_body">Body</label><br />
        <textarea cols="40" id="post_body" name="post[body]" rows="20">
          Back to the hill and over it again!
        </textarea>
      </p>
      <input type='submit' value='Create' />
    </form>

It’s possible to specialize the form builder by using a different action name and by supplying another block renderer. Example (entry is a new record that has a message attribute using VARCHAR):

  form("entry", :action => "sign", :input_block =>
       Proc.new { |record, column| "#{column.human_name}: #{input(record, column.name)}<br />" }) =>

    <form action='/post/sign' method='post'>
      Message:
      <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br />
      <input type='submit' value='Sign' />
    </form>

It’s also possible to add additional content to the form by giving it a block, such as:

  form("entry", :action => "sign") do |form|
    form << content_tag("b", "Department")
    form << collection_select("department", "id", @departments, "id", "name")
  end
Show source
Register or log in to add new notes.