The Depot Application

The Depot Application

23.6 Custom Form Builders 23.3 Helpers for Formatting, Linking, and Pagination

23.5 Forms That Wrap Model Objects

<"United States"> expected but was
<"Dave">.

Traceback:
  /home/rubys/git/awdwr/edition3/checkdepot.rb:1122
cp -rpv /home/rubys/git/awdwr/edition3/plugins/country_select vendor/plugins/
`/home/rubys/git/awdwr/edition3/plugins/country_select' -> `vendor/plugins/country_select'
`/home/rubys/git/awdwr/edition3/plugins/country_select/install.rb' -> `vendor/plugins/country_select/install.rb'
`/home/rubys/git/awdwr/edition3/plugins/country_select/MIT-LICENSE' -> `vendor/plugins/country_select/MIT-LICENSE'
`/home/rubys/git/awdwr/edition3/plugins/country_select/init.rb' -> `vendor/plugins/country_select/init.rb'
`/home/rubys/git/awdwr/edition3/plugins/country_select/uninstall.rb' -> `vendor/plugins/country_select/uninstall.rb'
`/home/rubys/git/awdwr/edition3/plugins/country_select/lib' -> `vendor/plugins/country_select/lib'
`/home/rubys/git/awdwr/edition3/plugins/country_select/lib/country_select.rb' -> `vendor/plugins/country_select/lib/country_select.rb'
`/home/rubys/git/awdwr/edition3/plugins/country_select/README' -> `vendor/plugins/country_select/README'

Restart the server.

rails generate model product title:string description:text image_url:string price:decimal
      invoke  active_record
      create    db/migrate/20120629192333_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/unit/product_test.rb
      create      test/fixtures/products.yml
cp -v /home/rubys/git/awdwr/edition3/data/code/e1/views/db/migrate/*products.rb db/migrate/*products.rb
`/home/rubys/git/awdwr/edition3/data/code/e1/views/db/migrate/002_create_products.rb' -> `db/migrate/20120629192333_create_products.rb'
cp -v /home/rubys/git/awdwr/edition3/data/code/e1/views/app/models/shipping.rb app/models
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/models/shipping.rb' -> `app/models/shipping.rb'
rails generate model detail product_id:integer sku:string manufacturer:string
      invoke  active_record
      create    db/migrate/20120629192337_create_details.rb
      create    app/models/detail.rb
      invoke    test_unit
      create      test/unit/detail_test.rb
      create      test/fixtures/details.yml
cp -v /home/rubys/git/awdwr/edition3/data/code/e1/views/db/migrate/*details.rb db/migrate/*details.rb
`/home/rubys/git/awdwr/edition3/data/code/e1/views/db/migrate/004_create_details.rb' -> `db/migrate/20120629192337_create_details.rb'
cp -v /home/rubys/git/awdwr/edition3/data/code/e1/views/app/models/detail.rb app/models
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/models/detail.rb' -> `app/models/detail.rb'
rake db:migrate
mv 20120629192333_create_products.rb 20110711000002_create_products.rb
mv 20120629192337_create_details.rb 20110711000003_create_details.rb
==  CreateProducts: migrating =================================================
-- create_table(:products)
   -> 0.0091s
==  CreateProducts: migrated (0.0092s) ========================================
 
==  CreateDetails: migrating ==================================================
-- create_table(:details)
   -> 0.0026s
==  CreateDetails: migrated (0.0028s) =========================================
 
cp -vr /home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/form_for app/views
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/form_for' -> `app/views/form_for'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/form_for/new.html.erb' -> `app/views/form_for/new.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/form_for/create.html.erb' -> `app/views/form_for/create.html.erb'
cp -vr /home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test app/views
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test' -> `app/views/test'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/calc.html.erb' -> `app/views/test/calc.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/example.html.rdoc' -> `app/views/test/example.html.rdoc'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/objects.xml.builder' -> `app/views/test/objects.xml.builder'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/date_dump.html.erb' -> `app/views/test/date_dump.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/select.html.erb' -> `app/views/test/select.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/test.html.erb' -> `app/views/test/test.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/date_format.reval' -> `app/views/test/date_format.reval'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/date_tags.html.erb' -> `app/views/test/date_tags.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/numbers.xml.builder' -> `app/views/test/numbers.xml.builder'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/text.xml.builder' -> `app/views/test/text.xml.builder'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/dates.xml.builder' -> `app/views/test/dates.xml.builder'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/calculate.html.erb' -> `app/views/test/calculate.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/t.html.erb' -> `app/views/test/t.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/test/example1.reval' -> `app/views/test/example1.reval'
cp -vr /home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/products app/views
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/products' -> `app/views/products'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/products/new.html.erb' -> `app/views/products/new.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/products/show.html.erb' -> `app/views/products/show.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/products/create.html.erb' -> `app/views/products/create.html.erb'
edit app/views/form_for/new.html.erb
<%= form_for :product, :url => { :action => :create } do |form| %>
  <p>Title:       <%= form.text_field :title, :size => 30 %></p>
  <p>Description: <%= form.text_area :description, :rows => 3 %></p>
  <p>Image URL:   <%= form.text_field :image_url %></p>
  <p>Price:       <%= form.text_field :price, :size => 10 %></p>
  <%= form.select :title, %w{ one two three } %>
  <p><%= submit_tag %></p>
<% end %>
edit app/views/test/select.html.erb
<% @user = "cat"
 
   def @user.id
     4
   end
 
   def @user.name
     "Dave"
   end
 
   def @user.country
     "United States"
   end  
 
   def @user.time_zone
    res = ActiveSupport::TimeZone[-6].name
   end
 
   @order = "dog"
   def @order.shipping_option
     101
   end    
  
%>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
 
<center>
<%= form_for :user do |form| %>
  <%= form.select(:name, %w{ Andy Bert Chas Dave Eric Fred }) %>
<% end %>
 
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<%= form_for :user do |form| %>
<%= form.select(:id, [ ['Andy', 1],
                       ['Bert', 2],
                       ['Chas', 3],
                       ['Dave', 4],
                       ['Eric', 5],
                       ['Fred', 6]]) 
%>
<% end %>
 
<p>&nbsp;</p>
 
<%= select(:user, :id, { 'Andy' => 1,
    'Bert' => 2,
    'Chas' => 3,
   'Dave' => 4,
   'Eric' => 5,
   'Fred' => 6}) %>
 
<p>&nbsp;</p>
 
<%= form_for :user do |form| %>
<%=
 @users = User.find(:all, :order => "name").map {|u| [u.name, u.id] }
 form.select(:name, @users)
%>
<% end %>
 
<b>xc</b>
 
<%= form_for :user do |form| %>
<%=
 @users = User.find(:all, :order => "name")
 form.collection_select(:name, @users, :id, :name)
%>
<% end %>
 
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
 
 
<%= country_select(:user, :country) %>
<p>&nbsp;</p>
 
<%= country_select(:user, :country, [ "United Kingom", "United States" ]) %>
<p>&nbsp;</p>
 
<%= time_zone_select(:user, :time_zone) %>
<p>&nbsp;</p>
 
<%= time_zone_select(:user, :time_zone, ActiveSupport::TimeZone.us_zones) %>
<p>&nbsp;</p>
 
 
<label for="order_shipping_option">Shipping: </label>
<select name="order[shipping_option]" id="order_shipping_option">
<%= 
  option_groups_from_collection_for_select(Shipping::OPTIONS, 
  					   :options, :type_name, # <- groups
					   :id,:name,            # <- items
					   @order.shipping_option)
 %>
</select>
 
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</center>
edit app/views/products/new.html.erb
<%= form_for :product, :url => { :action => :create } do |form| %>
  <%= error_messages_for :product %>
  Title:       <%= form.text_field :title %><br/>
  Description: <%= form.text_area :description, :rows => 3 %><br/>
  Image url:   <%=form.text_field :image_url  %><br/>
 
  <fieldset>
    <legend>Details...</legend>
    <%= error_messages_for :details %>
    <%= fields_for :details do |detail| %>
      SKU:          <%= detail.text_field :sku %><br/>
      Manufacturer: <%= detail.text_field :manufacturer %>
    <% end %>
  </fieldset>
  <%= submit_tag %>
<% end %>
edit app/views/upload_get.html.erb
get /form_for/new

Title:

Description:

Image URL:

Price:

get /test/select

 

 

 

 

 

 

 

 

 

 

 

xc

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

get /products/new
DEPRECATION WARNING: error_messages_for was removed from Rails and is now available as a plugin. Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`. (called from _app_views_products_new_html_erb__1461573374_70201630548720_0 at /home/rubys/git/awdwr/edition3/work-30/view/app/views/products/new.html.erb:2) Title:
Description:
Image url:
Details... DEPRECATION WARNING: error_messages_for was removed from Rails and is now available as a plugin. Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`. (called from _app_views_products_new_html_erb__1461573374_70201630548720_0 at /home/rubys/git/awdwr/edition3/work-30/view/app/views/products/new.html.erb:9) SKU:
Manufacturer:

23.6 Custom Form Builders 23.3 Helpers for Formatting, Linking, and Pagination