SlideShare a Scribd company logo
1 of 104
The 11th Round of ROR Lab.




Rails Form Helpers

        April 21th, 2012

        Hyoseong Choi
          ROR Lab.
Short Review


               ROR Lab.
Eager Loading
         Associations
- Conditions on Eager Loaded Associations -

      conditional “joins” > conditional “includes”


   Post.includes(:comments)
     .where("comments.visible", true)


  SELECT "posts"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5
  FROM "posts"
  LEFT OUTER JOIN "comments"
  ON "comments"."post_id" = "posts"."id"
  WHERE (comments.visible = 1)


                                                                       ROR Lab.
Eager Loading
         Associations
- Conditions on Eager Loaded Associations -
                      INNER JOIN                             LEFT OUTER JOIN
      conditional “joins” > conditional “includes”


   Post.includes(:comments)
     .where("comments.visible", true)


  SELECT "posts"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5
  FROM "posts"
  LEFT OUTER JOIN "comments"
  ON "comments"."post_id" = "posts"."id"
  WHERE (comments.visible = 1)


                                                                       ROR Lab.
Scopes
             Passing in arguments
class Post < ActiveRecord::Base
  scope :1_week_before,
  lambda { |time| where("created_at < ?", time) }
end




class Post < ActiveRecord::Base
  def self.1_week_before(time)
    where("created_at < ?", time)
  end
                      ***What about “as a class method” ?

                                                     ROR Lab.
Scopes
                   Passing in arguments
      class Post < ActiveRecord::Base
        scope :1_week_before,
        lambda { |time| where("created_at < ?", time) }
      end




           le
       eab
    erclass Post < ActiveRecord::Base
  ef
pr      def self.1_week_before(time)
          where("created_at < ?", time)
        end
                            ***What about “as a class method” ?

                                                           ROR Lab.
Form Helpers


               ROR Lab.
form_tag

• Two arguments
 1. path for action
 2. options hash
   • submission method
   • HTML options : class, ...
                                 ROR Lab.
form_tag
                        Basic Form

<%= form_tag do %>
  Form contents
<% end %>




<form accept-charset="UTF-8" action="/home/index" method="post">
  <div style="margin:0;padding:0">
    <input name="utf8" type="hidden" value="&#x2713;" />
    <input name="authenticity_token" type="hidden"
value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" />
  </div>
  Form contents
</form>




                                                                   ROR Lab.
form_tag
                 Multiple Hashes

form_tag(:controller => "people", :action => "search", :method
=> "get", :class => "nifty_form")

# => '<form accept-charset="UTF-8" action="/people/search?




form_tag({:controller => "people", :action => "search"}, :method
=> "get", :class => "nifty_form")

# => '<form accept-charset="UTF-8" action="/people/search"



                                                           ROR Lab.
Helpers
        Generating Form Elements
•   check_box_tag
•   radio_button_tag
•   text_area_tag
•   password_field_tag
•   hidden_field_tag
•   search_field_tag
•   telephone_field_tag
•   url_field_tag
•   email_field_tag


                                   ROR Lab.
Helpers
        Generating Form Elements
•   check_box_tag
•   radio_button_tag
•   text_area_tag
•   password_field_tag
•   hidden_field_tag
•   search_field_tag
•   telephone_field_tag
                         HTML5 controls
•   url_field_tag
•   email_field_tag


                                   ROR Lab.
Helpers
        Generating Form Elements
•   check_box_tag
•   radio_button_tag
•   text_area_tag
•   password_field_tag
•   hidden_field_tag         polyfiller
•   search_field_tag
•   telephone_field_tag
                         HTML5 controls
•   url_field_tag
•   email_field_tag


                                        ROR Lab.
Helpers
        Generating Form Elements
•   check_box_tag
•   radio_button_tag
•   text_area_tag
•   password_field_tag
•   hidden_field_tag         polyfiller
•   search_field_tag
•   telephone_field_tag
                         HTML5 controls
•   url_field_tag
•   email_field_tag


                                        ROR Lab.
Helpers
        Generating Form Elements
•   check_box_tag
•   radio_button_tag
•   text_area_tag           yepnope
•   password_field_tag
•   hidden_field_tag         polyfiller
•   search_field_tag
•   telephone_field_tag
                         HTML5 controls
•   url_field_tag
•   email_field_tag


                                        ROR Lab.
Helpers
        Generating Form Elements
•   check_box_tag
•   radio_button_tag       Modernizr
•   text_area_tag           yepnope
•   password_field_tag
•   hidden_field_tag         polyfiller
•   search_field_tag
•   telephone_field_tag
                         HTML5 controls
•   url_field_tag
•   email_field_tag


                                        ROR Lab.
HTML 5
               Form Helpers
   Rails 3                HTML5 Input Types
 search_field                        search
telephone_field                        tel
   url_field                           url
  email_field                         email
 number_field                       number
  range_field                        range
                   Agile Web Development with Rails 4th edition


                                                        ROR Lab.
Model Object
  Helpers




               ROR Lab.
Model Object
  Helpers

  •   check_box_tag




                      ROR Lab.
Model Object
  Helpers

  •   check_box_tag
  •   radio_button_tag




                         ROR Lab.
Model Object
  Helpers

  •   check_box_tag
  •   radio_button_tag
  •   text_area_tag




                         ROR Lab.
Model Object
  Helpers

  •   check_box_tag
  •   radio_button_tag
  •   text_area_tag
  •   password_field_tag




                          ROR Lab.
Model Object
  Helpers

  •   check_box_tag
  •   radio_button_tag
  •   text_area_tag
  •   password_field_tag
  •   hidden_field_tag




                          ROR Lab.
Model Object
      Helpers

            •   check_box_tag
            •   radio_button_tag
• No _tag   •   text_area_tag
            •   password_field_tag
            •   hidden_field_tag




                                    ROR Lab.
Model Object
      Helpers

            •   check_box_tag
            •   radio_button_tag
• No _tag   •   text_area_tag
            •   password_field_tag
            •   hidden_field_tag




                                    ROR Lab.
for Model Object
         @person -> name : “Henry”


<%= text_field(:person, :name) %>




<input id="person_name" name="person[name]" type="text"




                                                          ROR Lab.
for Model Object
         @person -> name : “Henry”


<%= text_field(:person, :name) %>




<input id="person_name" name="person[name]" type="text"




                                                          ROR Lab.
for Model Object
         @person -> name : “Henry”


<%= text_field(:person, :name) %>




<input id="person_name" name="person[name]" type="text"




                                                          ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
Binding a Form to
    an Object
def new
  @article = Article.new
end




<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




                                                            ROR Lab.
<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




<form accept-charset="UTF-8" action="/articles/create"
method="post" class="nifty_form">
  <input id="article_title" name="article[title]" size="30"
type="text" />
  <textarea id="article_body" name="article[body]" cols="60"
rows="12"></textarea>
  <input name="commit" type="submit" value="Create" />
</form>




                                                               ROR Lab.
<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




       params[:article]
<form accept-charset="UTF-8" action="/articles/create"
method="post" class="nifty_form">
  <input id="article_title" name="article[title]" size="30"
       params[:article][:title]
type="text" />
  <textarea id="article_body" name="article[body]" cols="60"
rows="12"></textarea>
  <input name="commit" type="submit" value="Create" />
</form>params[:article][:body]

                                                               ROR Lab.
<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




       params[:article]
<form accept-charset="UTF-8" action="/articles/create"
method="post" class="nifty_form">
  <input id="article_title" name="article[title]" size="30"
       params[:article][:title]
type="text" />
  <textarea id="article_body" name="article[body]" cols="60"
rows="12"></textarea>
  <input name="commit" type="submit" value="Create" />
</form>params[:article][:body]

                                                               ROR Lab.
<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




       params[:article]
<form accept-charset="UTF-8" action="/articles/create"
method="post" class="nifty_form">
  <input id="article_title" name="article[title]" size="30"
       params[:article][:title]
type="text" />
  <textarea id="article_body" name="article[body]" cols="60"
rows="12"></textarea>
  <input name="commit" type="submit" value="Create" />
</form>params[:article][:body]

                                                               ROR Lab.
<%= form_for @article, :url => { :action => "create" }, :html =>
{:class => "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, :size => "60x12" %>
  <%= f.submit "Create" %>
<% end %>




       params[:article]
<form accept-charset="UTF-8" action="/articles/create"
method="post" class="nifty_form">
  <input id="article_title" name="article[title]" size="30"
       params[:article][:title]
type="text" />
  <textarea id="article_body" name="article[body]" cols="60"
rows="12"></textarea>
  <input name="commit" type="submit" value="Create" />
</form>params[:article][:body]

                                                               ROR Lab.
fields_for


Dry Lab in Terminal




                      ROR Lab.
fields_for
Person
  •name
  •age
  •sex
  •address
  •telephone


                     ROR Lab.
fields_for
Person         Contact
  •name
  •age
  •sex
  •address
  •telephone


                         ROR Lab.
fields_for
Person          Contact
  •name           •address
  •age            •telephone
  •sex




                          ROR Lab.
fields_for
           has_one
Person               Contact
  •name                •address
  •age                 •telephone
  •sex




                               ROR Lab.
fields_for
           has_one
Person                Contact
  •name                 •address
  •age    belong_to     •telephone
  •sex




                                ROR Lab.
fields_for
                   has_one
Person                                  Contact
  •name                                   •address
  •age           belong_to                •telephone
  •sex
class Person < ActiveRecord::Base
 has_one :contact, :dependent => :destroy
end

class Contact < ActiveRecord::Base
 belongs_to :person



                                                  ROR Lab.
Using Resources
   resources :articles in config/routes.rb


## Creating a new article
# long-style:
form_for(@article, :url => articles_path)
# same thing, short-style (record identification gets used):
form_for(@article)
 
## Editing an existing article
# long-style:
form_for(@article, :url => article_path(@article), :html =>
{ :method => "put" })
# short-style:
form_for(@article)




                                                              ROR Lab.
Using Namespaces
namespace :admin do                  in routes.rb
  resources :posts, :comments
end




form_for [:admin, @post]        in _form.html.erb




                                           ROR Lab.
HTTP Verbs

• GET
           for all browsers
• POST
• PUT             ?
• DELETE
                              ROR Lab.
HTTP Verbs

• GET
           for all browsers
• POST
• PUT             ?
• DELETE
                              ROR Lab.
HTTP Verbs

• GET
           for all browsers
• POST
• PUT             ?
• DELETE
                              ROR Lab.
PUT & DELETE
       • A hidden input : _method
form_tag(search_path, :method => "put")




<form accept-charset="UTF-8" action="/search" method="post">
  <div style="margin:0;padding:0">
    <input name="_method" type="hidden" value="put" />
    <input name="utf8" type="hidden" value="&#x2713;" />
    <input name="authenticity_token" type="hidden"
value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" />
  </div>
  ...




                                                               ROR Lab.
select_tag
<select name="city_id" id="city_id">
  <option value="1">Lisbon</option>
  <option value="2">Madrid</option>
  ...
  <option value="12">Berlin</option>
</select>




<%= select_tag(:city_id, '<option value="1">Lisbon</option>...')
%>




                                                           ROR Lab.
options_for_select
 <%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...]) %>
  
 output:                  1st argument => a nested array
  
 <option value="1">Lisbon</option>
 <option value="2">Madrid</option>
 ...




 <%= select_tag(:city_id, options_for_select(...)) %>




                                                           ROR Lab.
options_for_select
 <%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>
  
 output:
                2nd argument => ‘selected’
 <option value="1">Lisbon</option>
 <option value="2" selected="selected">Madrid</option>




                                                                 ROR Lab.
options_for_select
 <%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>
  
 output:
                2nd argument => ‘selected’
 <option value="1">Lisbon</option>
 <option value="2" selected="selected">Madrid</option>




                                                                 ROR Lab.
_tag
              select_tag
# controller:
@person = Person.new(:city_id => 2)




# view:
<%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %>




                                                                   ROR Lab.
select_tag ORM
         for
# controller:
@person = Person.new(:city_id => 2)




# view:
<%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %>




                                                                   ROR Lab.
select_tag ORM
         for
# controller:
@person = Person.new(:city_id => 2)




# view:
<%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %>



                               2
                               pre-selected by Rails



                                                                   ROR Lab.
select_tag ORM
                        for
               # controller:
               @person = Person.new(:city_id => 2)




               # view:
               <%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %>
form builder




                                                2
                                                pre-selected by Rails
               # select on a form builder
               <%= f.select(:city_id, ...) %>


                                                                                  ROR Lab.
select from
            collection
<% cities_array = City.all.map { |city| [city.name, city.id] } %>
<%= options_for_select(cities_array) %>




   options _for_select




                                                                    ROR Lab.
select from
            collection
<% cities_array = City.all.map { |city| [city.name, city.id] } %>
<%= options_for_select(cities_array) %>




   options _from_collection                       _for_select
                                   (City.all, :id, :name)




                                                                    ROR Lab.
collection_select

<%= collection_select




<%= f.collection_select




                          ROR Lab.
collection_select

<%= collection_
    collection_select




<%= f.collection_select




                          ROR Lab.
collection_select

<%= collection_
    collection_select




<%= f.
    f.collection_select




                          ROR Lab.
Special Select
• time_zone_select
  : time_zone_options_for_select
• country_select
  : isolated to country_select plugin
• select_date : barebones helper
• date_select : model object helper
                                        ROR Lab.
select_date
<%= select_date Date.today, :prefix => :start_date %>




<select id="start_date_year"
     name="start_date[year]"> ... </select>
<select id="start_date_month"
     name="start_date[month]"> ... </select>
<select id="start_date_day"
     name="start_date[day]"> ... </select>




                                                       ROR Lab.
select_date
<%= select_date Date.today, :prefix => :start_date %>




<select id="start_date_year"
     name="start_date[year]"> ... </select>
<select id="start_date_month"
     name="start_date[month]"> ... </select>
<select id="start_date_day"
     name="start_date[day]"> ... </select>




Date.civil(params[:start_date][:year].to_i, params[:start_date]
[:month].to_i, params[:start_date][:day].to_i)




                                                              ROR Lab.
date_select
<%= date_select :person, :birth_date %>




<select id="person_birth_date_1i"
     name="person[birth_date(1i)]"> ... </select>
<select id="person_birth_date_2i"
     name="person[birth_date(2i)]"> ... </select>
<select id="person_birth_date_3i"




                                                    ROR Lab.
date_select
<%= date_select :person, :birth_date %>




<select id="person_birth_date_1i"
     name="person[birth_date(1i)]"> ... </select>
<select id="person_birth_date_2i"
     name="person[birth_date(2i)]"> ... </select>
<select id="person_birth_date_3i"




{:person => {'birth_date(1i)' => '2008', 'birth_date(2i)' => '11',




                                                               ROR Lab.
Individual Selects
• select_year
• select_month
• select_day      :prefix defaults to “date”
• select_hour
• select_minute
• select_second

                                   ROR Lab.
Individual Selects
• select_year
• select_month
• select_day      :prefix defaults to “date”
• select_hour
• select_minute
• select_second

                                   ROR Lab.
Uploading Files
params[:picture]
 <%= form_tag({:action => :upload}, :multipart => true) do %>
   <%= file_field_tag 'picture' %>
 <% end %>
  
 <%= form_for @person
                          , :multipart => true
   <%= f.file_field :picture %>                    do |f| %>
 <% end %>


params[:person][:picture]
Since Rails 3.1, it automatically sets the multipart/
form-data with file_field in the form_for
                                                          ROR Lab.
Uploading Files
params[:picture]
 <%= form_tag({:action => :upload}, :multipart => true) do %>
   <%= file_field_tag 'picture' %>
 <% end %>
  
 <%= form_for @person
   <%= f.file_field :picture %> |f| %>
                           do
 <% end %>


params[:person][:picture]
Since Rails 3.1, it automatically sets the multipart/
form-data with file_field in the form_for
                                                          ROR Lab.
Uploading Files
params[:picture]
 <%= form_tag({:action => :upload}, :multipart => true) do %>
   <%= file_field_tag 'picture' %>
 <% end %>
  
 <%= form_for @person
   <%= f.file_field :picture %> |f| %>
                           do
 <% end %>


params[:person][:picture]
Since Rails 3.1, it automatically sets the multipart/
form-data with file_field in the form_for
                                                          ROR Lab.
What gets
             uploaded
def upload
  uploaded_io = params[:person][:picture]
  File.open(Rails.root.join('public', 'uploads',
uploaded_io.original_filename), 'w') do |file|
    file.write(uploaded_io.read)
  end




                                                   ROR Lab.
What gets
             uploaded
def upload
  uploaded_io = params[:person][:picture]
  File.open(Rails.root.join('public', 'uploads',
uploaded_io.original_filename), 'w') do |file|
    file.write(uploaded_io.read)
  end




an instance of a subclass of IO
    • original_filename
    • content_type : MIME type
                                                   ROR Lab.
Upload Gems


• CarrierWave
• Paperclip


                  ROR Lab.
Ajaxing Upload

• “remotipart” gem
  : AJAX style file uploads with jQuery

  https://github.com/leppert/remotipart




                                          ROR Lab.
Customizing Form
    Builders




              ROR Lab.
Customizing Form
    Builders

<%= form_for @person do |f| %>
  <%= text_field_with_label f, :first_name %>




                                              ROR Lab.
Customizing Form
    Builders
<%= form_for @person do |f| %>
  <%= text_field_with_label f, :first_name %>




<%= form_for @person, :builder => LabellingFormBuilder do |f|
%>
  <%= f.text_field :first_name %>




class LabellingFormBuilder < ActionView::Helpers::FormBuilder
  def text_field(attribute, options={})
    label(attribute) + super
  end
end

                                                           ROR Lab.
Simple_form


• https://github.com/plataformatec/
  simple_form




                                      ROR Lab.
Params Naming
  Client                   Server

    Form
for model obj
 “@person”      params[:person]

   submit




                                    ROR Lab.
Params Naming
  Client           Server

    Form
for model obj
 “@person”      params[:person]

   submit




                             ROR Lab.
Basic Structures
                  Arrays & Hashes

<input id="person_name" name="person[name]"

    type="text" value="Henry"/>


params hash
            {‘person’ => {‘name’ => ‘Henry’}}

params[:person]
          {‘name’ => ‘Henry’}

params[:person][:name]
        ‘Henry’
                                                ROR Lab.
Nested Hashes
<input id="person_address_city"
    name="person[address][city]"
    type="text" value="New York"/>



params hash
        {'person' => {'address' => {'city' => 'New York'}}}




                                                              ROR Lab.
Duplicated Params
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>




params[:person][:phone_number]
        [
            ’02-333-1234’,
            ‘031-323-9898’,
            ‘062-546-2323’
        ]
                                                      ROR Lab.
Duplicated Params
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>




params[:person][:phone_number]
        [
            ’02-333-1234’,
            ‘031-323-9898’,
            ‘062-546-2323’
        ]
                                                      ROR Lab.
Duplicated Params
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>




params[:person][:phone_number]
        [
            ’02-333-1234’,
            ‘031-323-9898’,
            ‘062-546-2323’
        ]
                                                      ROR Lab.
Duplicated Params
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>
 <input name="person[phone_number][]" type="text"/>




params[:person][:phone_number]
        [
            ’02-333-1234’,
            ‘031-323-9898’,
            ‘062-546-2323’
        ]
                                                      ROR Lab.
Mixed Params
   hash nth-nested but array only one-level

<input name="addresses[][line1]" type="text"/>
<input name="addresses[][line2]" type="text"/>
<input name="addresses[][city]" type="text"/>



params[:addresses]
       [
           {
               ‘line1’ => ’02-333-1234’,
               ‘line2’ => ‘031-323-9898’,
               ‘city’ => ‘seoul’
           }
       ]
                                                 ROR Lab.
Using Form
               Helpers
<%= form_for @person do |person_form| %>
  <%= person_form.text_field :name %>
  <% @person.addresses.each do |address| %>
    <%= person_form.fields_for address, :index => address do |
address_form|%>
      <%= address_form.text_field :city %>
    <% end %>
  <% end %>
<% end %>



<form accept-charset="UTF-8" action="/people/1" class="edit_person" id="edit_person_1"
method="post">
  <input id="person_name" name="person[name]" size="30" type="text" />
  <input id="person_address_23_city" name="person[address][23][city]" size="30" type="text" />
  <input id="person_address_45_city" name="person[address][45][city]" size="30" type="text" />
</form>




                                                                                            ROR Lab.
Using Form
             Helpers
{
    'person' =>
    {
      'name' => 'Bob',
      'address' =>
      {
        '23' => {'city' => 'Paris'},
        '45' => {'city' => 'London'}
      }
    }




                                       ROR Lab.
Using :index

<%= fields_for 'person[address][primary]', address, :index =>
address do |address_form| %>
  <%= address_form.text_field :city %>




<%= fields_for 'person[address][primary][]', address do |
address_form| %>
  <%= address_form.text_field :city %>




                                                           ROR Lab.
Form to External
  Resources - 1
<%= form_tag 'http://farfar.away/form', :authenticity_token =>
'external_token') do %>
  Form contents




<%= form_tag 'http://farfar.away/form', :authenticity_token =>
false) do %>
  Form contents




                                                          ROR Lab.
Form to External
  Resources - 1
<%= form_tag 'http://farfar.away/form', :authenticity_token =>
'external_token') do %>
  Form contents
                               payment gateway

<%= form_tag 'http://farfar.away/form', :authenticity_token =>
false) do %>
  Form contents




                                                          ROR Lab.
Form to External
  Resources - 1
<%= form_tag 'http://farfar.away/form', :authenticity_token =>
'external_token') do %>
  Form contents




<%= form_tag 'http://farfar.away/form', :authenticity_token =>
false) do %>
  Form contents
                      payment gateway


                                                          ROR Lab.
Form to External
  Resources - 2
<%= form_for @invoice, :url =>
external_url, :authenticity_token => 'external_token' do |f|
  Form contents
<% end %>




<%= form_for @invoice, :url =>
external_url, :authenticity_token => false do |f|
  Form contents




                                                               ROR Lab.
Form to External
  Resources - 2
<%= form_for @invoice, :url =>
     form_for
external_url, :authenticity_token => 'external_token' do |f|
  Form contents
<% end %>




<%= form_for @invoice, :url =>
     form_for
external_url, :authenticity_token => false do |f|
  Form contents




                                                               ROR Lab.
Complex forms
Railscasts by Ryan Bates




                           ROR Lab.
Complex forms
Railscasts by Ryan Bates

•   Complex Forms Part 1 - Episode #73

•   Complex Forms Part II - Episode #74

•   Complex Forms Part III - Episode #75

•   Nested Model Form (resivsed) - Episode #196


                                           ROR Lab.
감사합니다.

More Related Content

Viewers also liked

레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개RORLAB
 
Getting Started with Rails (3)
Getting Started with Rails (3) Getting Started with Rails (3)
Getting Started with Rails (3) RORLAB
 
Active Support Core Extension (3)
Active Support Core Extension (3)Active Support Core Extension (3)
Active Support Core Extension (3)RORLAB
 
Getting Started with Rails (1)
Getting Started with Rails (1)Getting Started with Rails (1)
Getting Started with Rails (1)RORLAB
 
Getting Started with Rails (4)
Getting Started with Rails (4) Getting Started with Rails (4)
Getting Started with Rails (4) RORLAB
 
Action Controller Overview, Season 1
Action Controller Overview, Season 1Action Controller Overview, Season 1
Action Controller Overview, Season 1RORLAB
 

Viewers also liked (6)

레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
 
Getting Started with Rails (3)
Getting Started with Rails (3) Getting Started with Rails (3)
Getting Started with Rails (3)
 
Active Support Core Extension (3)
Active Support Core Extension (3)Active Support Core Extension (3)
Active Support Core Extension (3)
 
Getting Started with Rails (1)
Getting Started with Rails (1)Getting Started with Rails (1)
Getting Started with Rails (1)
 
Getting Started with Rails (4)
Getting Started with Rails (4) Getting Started with Rails (4)
Getting Started with Rails (4)
 
Action Controller Overview, Season 1
Action Controller Overview, Season 1Action Controller Overview, Season 1
Action Controller Overview, Season 1
 

Similar to Active Record Form Helpers, Season 1

Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Wongnai
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2RORLAB
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API ResponsesPrairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API Responsesdarrelmiller71
 
Mongo and Harmony
Mongo and HarmonyMongo and Harmony
Mongo and HarmonySteve Smith
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2RORLAB
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Django Overview
Django OverviewDjango Overview
Django OverviewBrian Tol
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecordMark Menard
 
Api's and ember js
Api's and ember jsApi's and ember js
Api's and ember jsEdwin Cruz
 
Let's read code: python-requests library
Let's read code: python-requests libraryLet's read code: python-requests library
Let's read code: python-requests librarySusan Tan
 
Open Social In The Enterprise
Open Social In The EnterpriseOpen Social In The Enterprise
Open Social In The EnterpriseTim Moore
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Routing 1, Season 1
Routing 1, Season 1Routing 1, Season 1
Routing 1, Season 1RORLAB
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperGiordano Scalzo
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialYi-Ting Cheng
 
Test driven development with behat and silex
Test driven development with behat and silexTest driven development with behat and silex
Test driven development with behat and silexDionyshs Tsoumas
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails Mohit Jain
 

Similar to Active Record Form Helpers, Season 1 (20)

Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API ResponsesPrairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API Responses
 
Mongo and Harmony
Mongo and HarmonyMongo and Harmony
Mongo and Harmony
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
 
Api's and ember js
Api's and ember jsApi's and ember js
Api's and ember js
 
mashraqi_farhan
mashraqi_farhanmashraqi_farhan
mashraqi_farhan
 
Let's read code: python-requests library
Let's read code: python-requests libraryLet's read code: python-requests library
Let's read code: python-requests library
 
Open Social In The Enterprise
Open Social In The EnterpriseOpen Social In The Enterprise
Open Social In The Enterprise
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Routing 1, Season 1
Routing 1, Season 1Routing 1, Season 1
Routing 1, Season 1
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapper
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Test driven development with behat and silex
Test driven development with behat and silexTest driven development with behat and silex
Test driven development with behat and silex
 
behat
behatbehat
behat
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
TDD with phpspec2
TDD with phpspec2TDD with phpspec2
TDD with phpspec2
 

More from RORLAB

Getting Started with Rails (2)
Getting Started with Rails (2)Getting Started with Rails (2)
Getting Started with Rails (2)RORLAB
 
Self join in active record association
Self join in active record associationSelf join in active record association
Self join in active record associationRORLAB
 
Asset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on RailsAsset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on RailsRORLAB
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)RORLAB
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)RORLAB
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2RORLAB
 
Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2RORLAB
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2RORLAB
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2RORLAB
 
Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2RORLAB
 
Active Record Association (2), Season 2
Active Record Association (2), Season 2Active Record Association (2), Season 2
Active Record Association (2), Season 2RORLAB
 
ActiveRecord Association (1), Season 2
ActiveRecord Association (1), Season 2ActiveRecord Association (1), Season 2
ActiveRecord Association (1), Season 2RORLAB
 
ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2RORLAB
 
ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2RORLAB
 
Rails Database Migration, Season 2
Rails Database Migration, Season 2Rails Database Migration, Season 2
Rails Database Migration, Season 2RORLAB
 
Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2RORLAB
 
Getting started with Rails (3), Season 2
Getting started with Rails (3), Season 2Getting started with Rails (3), Season 2
Getting started with Rails (3), Season 2RORLAB
 
Getting started with Rails (1), Season 2
Getting started with Rails (1), Season 2Getting started with Rails (1), Season 2
Getting started with Rails (1), Season 2RORLAB
 
Routing 2, Season 1
Routing 2, Season 1Routing 2, Season 1
Routing 2, Season 1RORLAB
 
Active Record Query Interface (2), Season 1
Active Record Query Interface (2), Season 1Active Record Query Interface (2), Season 1
Active Record Query Interface (2), Season 1RORLAB
 

More from RORLAB (20)

Getting Started with Rails (2)
Getting Started with Rails (2)Getting Started with Rails (2)
Getting Started with Rails (2)
 
Self join in active record association
Self join in active record associationSelf join in active record association
Self join in active record association
 
Asset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on RailsAsset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on Rails
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2
 
Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2
 
Active Record Association (2), Season 2
Active Record Association (2), Season 2Active Record Association (2), Season 2
Active Record Association (2), Season 2
 
ActiveRecord Association (1), Season 2
ActiveRecord Association (1), Season 2ActiveRecord Association (1), Season 2
ActiveRecord Association (1), Season 2
 
ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2
 
ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2
 
Rails Database Migration, Season 2
Rails Database Migration, Season 2Rails Database Migration, Season 2
Rails Database Migration, Season 2
 
Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2
 
Getting started with Rails (3), Season 2
Getting started with Rails (3), Season 2Getting started with Rails (3), Season 2
Getting started with Rails (3), Season 2
 
Getting started with Rails (1), Season 2
Getting started with Rails (1), Season 2Getting started with Rails (1), Season 2
Getting started with Rails (1), Season 2
 
Routing 2, Season 1
Routing 2, Season 1Routing 2, Season 1
Routing 2, Season 1
 
Active Record Query Interface (2), Season 1
Active Record Query Interface (2), Season 1Active Record Query Interface (2), Season 1
Active Record Query Interface (2), Season 1
 

Recently uploaded

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 

Recently uploaded (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 

Active Record Form Helpers, Season 1

  • 1. The 11th Round of ROR Lab. Rails Form Helpers April 21th, 2012 Hyoseong Choi ROR Lab.
  • 2. Short Review ROR Lab.
  • 3. Eager Loading Associations - Conditions on Eager Loaded Associations - conditional “joins” > conditional “includes” Post.includes(:comments) .where("comments.visible", true) SELECT "posts"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5 FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE (comments.visible = 1) ROR Lab.
  • 4. Eager Loading Associations - Conditions on Eager Loaded Associations - INNER JOIN LEFT OUTER JOIN conditional “joins” > conditional “includes” Post.includes(:comments) .where("comments.visible", true) SELECT "posts"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5 FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE (comments.visible = 1) ROR Lab.
  • 5. Scopes Passing in arguments class Post < ActiveRecord::Base   scope :1_week_before, lambda { |time| where("created_at < ?", time) } end class Post < ActiveRecord::Base   def self.1_week_before(time)     where("created_at < ?", time)   end ***What about “as a class method” ? ROR Lab.
  • 6. Scopes Passing in arguments class Post < ActiveRecord::Base   scope :1_week_before, lambda { |time| where("created_at < ?", time) } end le eab erclass Post < ActiveRecord::Base ef pr   def self.1_week_before(time)     where("created_at < ?", time)   end ***What about “as a class method” ? ROR Lab.
  • 7. Form Helpers ROR Lab.
  • 8. form_tag • Two arguments 1. path for action 2. options hash • submission method • HTML options : class, ... ROR Lab.
  • 9. form_tag Basic Form <%= form_tag do %>   Form contents <% end %> <form accept-charset="UTF-8" action="/home/index" method="post">   <div style="margin:0;padding:0">     <input name="utf8" type="hidden" value="&#x2713;" />     <input name="authenticity_token" type="hidden" value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" />   </div>   Form contents </form> ROR Lab.
  • 10. form_tag Multiple Hashes form_tag(:controller => "people", :action => "search", :method => "get", :class => "nifty_form") # => '<form accept-charset="UTF-8" action="/people/search? form_tag({:controller => "people", :action => "search"}, :method => "get", :class => "nifty_form") # => '<form accept-charset="UTF-8" action="/people/search" ROR Lab.
  • 11. Helpers Generating Form Elements • check_box_tag • radio_button_tag • text_area_tag • password_field_tag • hidden_field_tag • search_field_tag • telephone_field_tag • url_field_tag • email_field_tag ROR Lab.
  • 12. Helpers Generating Form Elements • check_box_tag • radio_button_tag • text_area_tag • password_field_tag • hidden_field_tag • search_field_tag • telephone_field_tag HTML5 controls • url_field_tag • email_field_tag ROR Lab.
  • 13. Helpers Generating Form Elements • check_box_tag • radio_button_tag • text_area_tag • password_field_tag • hidden_field_tag polyfiller • search_field_tag • telephone_field_tag HTML5 controls • url_field_tag • email_field_tag ROR Lab.
  • 14. Helpers Generating Form Elements • check_box_tag • radio_button_tag • text_area_tag • password_field_tag • hidden_field_tag polyfiller • search_field_tag • telephone_field_tag HTML5 controls • url_field_tag • email_field_tag ROR Lab.
  • 15. Helpers Generating Form Elements • check_box_tag • radio_button_tag • text_area_tag yepnope • password_field_tag • hidden_field_tag polyfiller • search_field_tag • telephone_field_tag HTML5 controls • url_field_tag • email_field_tag ROR Lab.
  • 16. Helpers Generating Form Elements • check_box_tag • radio_button_tag Modernizr • text_area_tag yepnope • password_field_tag • hidden_field_tag polyfiller • search_field_tag • telephone_field_tag HTML5 controls • url_field_tag • email_field_tag ROR Lab.
  • 17. HTML 5 Form Helpers Rails 3 HTML5 Input Types search_field search telephone_field tel url_field url email_field email number_field number range_field range Agile Web Development with Rails 4th edition ROR Lab.
  • 18. Model Object Helpers ROR Lab.
  • 19. Model Object Helpers • check_box_tag ROR Lab.
  • 20. Model Object Helpers • check_box_tag • radio_button_tag ROR Lab.
  • 21. Model Object Helpers • check_box_tag • radio_button_tag • text_area_tag ROR Lab.
  • 22. Model Object Helpers • check_box_tag • radio_button_tag • text_area_tag • password_field_tag ROR Lab.
  • 23. Model Object Helpers • check_box_tag • radio_button_tag • text_area_tag • password_field_tag • hidden_field_tag ROR Lab.
  • 24. Model Object Helpers • check_box_tag • radio_button_tag • No _tag • text_area_tag • password_field_tag • hidden_field_tag ROR Lab.
  • 25. Model Object Helpers • check_box_tag • radio_button_tag • No _tag • text_area_tag • password_field_tag • hidden_field_tag ROR Lab.
  • 26. for Model Object @person -> name : “Henry” <%= text_field(:person, :name) %> <input id="person_name" name="person[name]" type="text" ROR Lab.
  • 27. for Model Object @person -> name : “Henry” <%= text_field(:person, :name) %> <input id="person_name" name="person[name]" type="text" ROR Lab.
  • 28. for Model Object @person -> name : “Henry” <%= text_field(:person, :name) %> <input id="person_name" name="person[name]" type="text" ROR Lab.
  • 29. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 30. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 31. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 32. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 33. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 34. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 35. Binding a Form to an Object def new   @article = Article.new end <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> ROR Lab.
  • 36. <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> <form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form">   <input id="article_title" name="article[title]" size="30" type="text" />   <textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>   <input name="commit" type="submit" value="Create" /> </form> ROR Lab.
  • 37. <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> params[:article] <form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form">   <input id="article_title" name="article[title]" size="30" params[:article][:title] type="text" />   <textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>   <input name="commit" type="submit" value="Create" /> </form>params[:article][:body] ROR Lab.
  • 38. <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> params[:article] <form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form">   <input id="article_title" name="article[title]" size="30" params[:article][:title] type="text" />   <textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>   <input name="commit" type="submit" value="Create" /> </form>params[:article][:body] ROR Lab.
  • 39. <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> params[:article] <form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form">   <input id="article_title" name="article[title]" size="30" params[:article][:title] type="text" />   <textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>   <input name="commit" type="submit" value="Create" /> </form>params[:article][:body] ROR Lab.
  • 40. <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>   <%= f.text_field :title %>   <%= f.text_area :body, :size => "60x12" %>   <%= f.submit "Create" %> <% end %> params[:article] <form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form">   <input id="article_title" name="article[title]" size="30" params[:article][:title] type="text" />   <textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>   <input name="commit" type="submit" value="Create" /> </form>params[:article][:body] ROR Lab.
  • 41. fields_for Dry Lab in Terminal ROR Lab.
  • 42. fields_for Person •name •age •sex •address •telephone ROR Lab.
  • 43. fields_for Person Contact •name •age •sex •address •telephone ROR Lab.
  • 44. fields_for Person Contact •name •address •age •telephone •sex ROR Lab.
  • 45. fields_for has_one Person Contact •name •address •age •telephone •sex ROR Lab.
  • 46. fields_for has_one Person Contact •name •address •age belong_to •telephone •sex ROR Lab.
  • 47. fields_for has_one Person Contact •name •address •age belong_to •telephone •sex class Person < ActiveRecord::Base has_one :contact, :dependent => :destroy end class Contact < ActiveRecord::Base belongs_to :person ROR Lab.
  • 48. Using Resources resources :articles in config/routes.rb ## Creating a new article # long-style: form_for(@article, :url => articles_path) # same thing, short-style (record identification gets used): form_for(@article)   ## Editing an existing article # long-style: form_for(@article, :url => article_path(@article), :html => { :method => "put" }) # short-style: form_for(@article) ROR Lab.
  • 49. Using Namespaces namespace :admin do in routes.rb   resources :posts, :comments end form_for [:admin, @post] in _form.html.erb ROR Lab.
  • 50. HTTP Verbs • GET for all browsers • POST • PUT ? • DELETE ROR Lab.
  • 51. HTTP Verbs • GET for all browsers • POST • PUT ? • DELETE ROR Lab.
  • 52. HTTP Verbs • GET for all browsers • POST • PUT ? • DELETE ROR Lab.
  • 53. PUT & DELETE • A hidden input : _method form_tag(search_path, :method => "put") <form accept-charset="UTF-8" action="/search" method="post">   <div style="margin:0;padding:0">     <input name="_method" type="hidden" value="put" />     <input name="utf8" type="hidden" value="&#x2713;" />     <input name="authenticity_token" type="hidden" value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" />   </div>   ... ROR Lab.
  • 54. select_tag <select name="city_id" id="city_id">   <option value="1">Lisbon</option>   <option value="2">Madrid</option>   ...   <option value="12">Berlin</option> </select> <%= select_tag(:city_id, '<option value="1">Lisbon</option>...') %> ROR Lab.
  • 55. options_for_select <%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...]) %>   output: 1st argument => a nested array   <option value="1">Lisbon</option> <option value="2">Madrid</option> ... <%= select_tag(:city_id, options_for_select(...)) %> ROR Lab.
  • 56. options_for_select <%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>   output:   2nd argument => ‘selected’ <option value="1">Lisbon</option> <option value="2" selected="selected">Madrid</option> ROR Lab.
  • 57. options_for_select <%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>   output:   2nd argument => ‘selected’ <option value="1">Lisbon</option> <option value="2" selected="selected">Madrid</option> ROR Lab.
  • 58. _tag select_tag # controller: @person = Person.new(:city_id => 2) # view: <%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %> ROR Lab.
  • 59. select_tag ORM for # controller: @person = Person.new(:city_id => 2) # view: <%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %> ROR Lab.
  • 60. select_tag ORM for # controller: @person = Person.new(:city_id => 2) # view: <%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %> 2 pre-selected by Rails ROR Lab.
  • 61. select_tag ORM for # controller: @person = Person.new(:city_id => 2) # view: <%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %> form builder 2 pre-selected by Rails # select on a form builder <%= f.select(:city_id, ...) %> ROR Lab.
  • 62. select from collection <% cities_array = City.all.map { |city| [city.name, city.id] } %> <%= options_for_select(cities_array) %> options _for_select ROR Lab.
  • 63. select from collection <% cities_array = City.all.map { |city| [city.name, city.id] } %> <%= options_for_select(cities_array) %> options _from_collection _for_select (City.all, :id, :name) ROR Lab.
  • 65. collection_select <%= collection_ collection_select <%= f.collection_select ROR Lab.
  • 66. collection_select <%= collection_ collection_select <%= f. f.collection_select ROR Lab.
  • 67. Special Select • time_zone_select : time_zone_options_for_select • country_select : isolated to country_select plugin • select_date : barebones helper • date_select : model object helper ROR Lab.
  • 68. select_date <%= select_date Date.today, :prefix => :start_date %> <select id="start_date_year" name="start_date[year]"> ... </select> <select id="start_date_month" name="start_date[month]"> ... </select> <select id="start_date_day" name="start_date[day]"> ... </select> ROR Lab.
  • 69. select_date <%= select_date Date.today, :prefix => :start_date %> <select id="start_date_year" name="start_date[year]"> ... </select> <select id="start_date_month" name="start_date[month]"> ... </select> <select id="start_date_day" name="start_date[day]"> ... </select> Date.civil(params[:start_date][:year].to_i, params[:start_date] [:month].to_i, params[:start_date][:day].to_i) ROR Lab.
  • 70. date_select <%= date_select :person, :birth_date %> <select id="person_birth_date_1i" name="person[birth_date(1i)]"> ... </select> <select id="person_birth_date_2i" name="person[birth_date(2i)]"> ... </select> <select id="person_birth_date_3i" ROR Lab.
  • 71. date_select <%= date_select :person, :birth_date %> <select id="person_birth_date_1i" name="person[birth_date(1i)]"> ... </select> <select id="person_birth_date_2i" name="person[birth_date(2i)]"> ... </select> <select id="person_birth_date_3i" {:person => {'birth_date(1i)' => '2008', 'birth_date(2i)' => '11', ROR Lab.
  • 72. Individual Selects • select_year • select_month • select_day :prefix defaults to “date” • select_hour • select_minute • select_second ROR Lab.
  • 73. Individual Selects • select_year • select_month • select_day :prefix defaults to “date” • select_hour • select_minute • select_second ROR Lab.
  • 74. Uploading Files params[:picture] <%= form_tag({:action => :upload}, :multipart => true) do %>   <%= file_field_tag 'picture' %> <% end %>   <%= form_for @person , :multipart => true   <%= f.file_field :picture %> do |f| %> <% end %> params[:person][:picture] Since Rails 3.1, it automatically sets the multipart/ form-data with file_field in the form_for ROR Lab.
  • 75. Uploading Files params[:picture] <%= form_tag({:action => :upload}, :multipart => true) do %>   <%= file_field_tag 'picture' %> <% end %>   <%= form_for @person   <%= f.file_field :picture %> |f| %> do <% end %> params[:person][:picture] Since Rails 3.1, it automatically sets the multipart/ form-data with file_field in the form_for ROR Lab.
  • 76. Uploading Files params[:picture] <%= form_tag({:action => :upload}, :multipart => true) do %>   <%= file_field_tag 'picture' %> <% end %>   <%= form_for @person   <%= f.file_field :picture %> |f| %> do <% end %> params[:person][:picture] Since Rails 3.1, it automatically sets the multipart/ form-data with file_field in the form_for ROR Lab.
  • 77. What gets uploaded def upload   uploaded_io = params[:person][:picture]   File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|     file.write(uploaded_io.read)   end ROR Lab.
  • 78. What gets uploaded def upload   uploaded_io = params[:person][:picture]   File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|     file.write(uploaded_io.read)   end an instance of a subclass of IO • original_filename • content_type : MIME type ROR Lab.
  • 79. Upload Gems • CarrierWave • Paperclip ROR Lab.
  • 80. Ajaxing Upload • “remotipart” gem : AJAX style file uploads with jQuery https://github.com/leppert/remotipart ROR Lab.
  • 81. Customizing Form Builders ROR Lab.
  • 82. Customizing Form Builders <%= form_for @person do |f| %>   <%= text_field_with_label f, :first_name %> ROR Lab.
  • 83. Customizing Form Builders <%= form_for @person do |f| %>   <%= text_field_with_label f, :first_name %> <%= form_for @person, :builder => LabellingFormBuilder do |f| %>   <%= f.text_field :first_name %> class LabellingFormBuilder < ActionView::Helpers::FormBuilder   def text_field(attribute, options={})     label(attribute) + super   end end ROR Lab.
  • 85. Params Naming Client Server Form for model obj “@person” params[:person] submit ROR Lab.
  • 86. Params Naming Client Server Form for model obj “@person” params[:person] submit ROR Lab.
  • 87. Basic Structures Arrays & Hashes <input id="person_name" name="person[name]" type="text" value="Henry"/> params hash {‘person’ => {‘name’ => ‘Henry’}} params[:person] {‘name’ => ‘Henry’} params[:person][:name] ‘Henry’ ROR Lab.
  • 88. Nested Hashes <input id="person_address_city" name="person[address][city]" type="text" value="New York"/> params hash {'person' => {'address' => {'city' => 'New York'}}} ROR Lab.
  • 89. Duplicated Params <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> params[:person][:phone_number] [ ’02-333-1234’, ‘031-323-9898’, ‘062-546-2323’ ] ROR Lab.
  • 90. Duplicated Params <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> params[:person][:phone_number] [ ’02-333-1234’, ‘031-323-9898’, ‘062-546-2323’ ] ROR Lab.
  • 91. Duplicated Params <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> params[:person][:phone_number] [ ’02-333-1234’, ‘031-323-9898’, ‘062-546-2323’ ] ROR Lab.
  • 92. Duplicated Params <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> <input name="person[phone_number][]" type="text"/> params[:person][:phone_number] [ ’02-333-1234’, ‘031-323-9898’, ‘062-546-2323’ ] ROR Lab.
  • 93. Mixed Params hash nth-nested but array only one-level <input name="addresses[][line1]" type="text"/> <input name="addresses[][line2]" type="text"/> <input name="addresses[][city]" type="text"/> params[:addresses] [ { ‘line1’ => ’02-333-1234’, ‘line2’ => ‘031-323-9898’, ‘city’ => ‘seoul’ } ] ROR Lab.
  • 94. Using Form Helpers <%= form_for @person do |person_form| %>   <%= person_form.text_field :name %>   <% @person.addresses.each do |address| %>     <%= person_form.fields_for address, :index => address do | address_form|%>       <%= address_form.text_field :city %>     <% end %>   <% end %> <% end %> <form accept-charset="UTF-8" action="/people/1" class="edit_person" id="edit_person_1" method="post">   <input id="person_name" name="person[name]" size="30" type="text" />   <input id="person_address_23_city" name="person[address][23][city]" size="30" type="text" />   <input id="person_address_45_city" name="person[address][45][city]" size="30" type="text" /> </form> ROR Lab.
  • 95. Using Form Helpers { 'person' => { 'name' => 'Bob', 'address' => { '23' => {'city' => 'Paris'}, '45' => {'city' => 'London'} } } ROR Lab.
  • 96. Using :index <%= fields_for 'person[address][primary]', address, :index => address do |address_form| %>   <%= address_form.text_field :city %> <%= fields_for 'person[address][primary][]', address do | address_form| %>   <%= address_form.text_field :city %> ROR Lab.
  • 97. Form to External Resources - 1 <%= form_tag 'http://farfar.away/form', :authenticity_token => 'external_token') do %>   Form contents <%= form_tag 'http://farfar.away/form', :authenticity_token => false) do %>   Form contents ROR Lab.
  • 98. Form to External Resources - 1 <%= form_tag 'http://farfar.away/form', :authenticity_token => 'external_token') do %>   Form contents payment gateway <%= form_tag 'http://farfar.away/form', :authenticity_token => false) do %>   Form contents ROR Lab.
  • 99. Form to External Resources - 1 <%= form_tag 'http://farfar.away/form', :authenticity_token => 'external_token') do %>   Form contents <%= form_tag 'http://farfar.away/form', :authenticity_token => false) do %>   Form contents payment gateway ROR Lab.
  • 100. Form to External Resources - 2 <%= form_for @invoice, :url => external_url, :authenticity_token => 'external_token' do |f|   Form contents <% end %> <%= form_for @invoice, :url => external_url, :authenticity_token => false do |f|   Form contents ROR Lab.
  • 101. Form to External Resources - 2 <%= form_for @invoice, :url => form_for external_url, :authenticity_token => 'external_token' do |f|   Form contents <% end %> <%= form_for @invoice, :url => form_for external_url, :authenticity_token => false do |f|   Form contents ROR Lab.
  • 102. Complex forms Railscasts by Ryan Bates ROR Lab.
  • 103. Complex forms Railscasts by Ryan Bates • Complex Forms Part 1 - Episode #73 • Complex Forms Part II - Episode #74 • Complex Forms Part III - Episode #75 • Nested Model Form (resivsed) - Episode #196 ROR Lab.
  • 105.   ROR Lab.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n