Screencast: Formtastic Teil 2

In der letzten Woche hat Ryan Bates Formtastic vorgestellt. In seinem neuen Screencasts geht er tiefer in den Funktionaumfang ein und erklärt vorgeschrittene Themen wie: many-to-many Beziehungen, Pflichtfelder und der Gestaltung von Formularen.

Download (19.7 MB, 9:11)
Alternativer Download für iPod & Apple TV(12.6 MB, 9:11)

Resourcen:

Quellcode:

[bash]
script/generate nifty_scaffold problem name:string
rake db:migrate
script/generate nifty_scaffold symptom animal_id:integer problem_id:integer –skip-controller
script/plugin install git://github.com/redinger/validation_reflection.git
[/bash]

[ruby]
# models/animal.rb
class Animal < ActiveRecord::Base
attr_accessible :name, :category_id, :born_on, :female, :problem_ids
belongs_to :category
has_many :symptoms
has_many :problems, :through => :symptoms
validates_presence_of :name, :born_on
end

# models/problem.rb
class Problem < ActiveRecord::Base
attr_accessible :name
has_many :symptoms
has_many :animals, :through => :symptoms
end

# models/symptom.rb
class Symptom < ActiveRecord::Base
attr_accessible :animal_id, :problem_id
belongs_to :animial
belongs_to :problem
end

# config/initializers/formtastic_config.rb
Formtastic::SemanticFormBuilder.inline_errors = :none
[/ruby]

[javascript]
/* formtastic_changes.css */
form.formtastic fieldset ol li p.inline-hints {
font-style: italic;
font-size: 11px;
}
[/javascript]

[html]

<!– views/animals/_form.html.erb –>
<% semantic_form_for @animal do |f| %>
<%= f.error_messages %>
<% f.inputs do %>
<%= f.input :name, :hint => "Use the owner’s name if none is provided" %>
<%= f.input :born_on, :start_year => 1900 %>
<%= f.input :category, :include_blank => false %>
<%= f.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %>
<%= f.input :problems, :as => :check_boxes, :required => false %>
<% end %>
<%= f.buttons %>
<% end %>
[/html]

Screencast: Formtastic Teil 1

Formtastic, ein Hilfmittel um die Arbeit mit Views zu vereinfachen, ist das heutige Thema in dem Screencst von Ryan Bates.

Download(19.7 MB, 10:41)
Alternativer Download für iPod & Apple TV (12.7 MB, 10:41)

Resourcen:

[bash]
rails vet
sudo rake gems:install
script/generate nifty_layout
script/generate nifty_scaffold category name:string description:text
rake db:migrate
script/generate formtastic_stylesheets
script/generate nifty_scaffold animal name:string category_id:integer born_on:date female:boolean
[/bash]

[html]
<!– application.html.erb –>
<%= stylesheet_link_tag ‚application‘, ‚formtastic‘, ‚formtastic_changes‘, :cache => "base" %>

<!– views/animals/_form.html.erb –>
<% semantic_form_for @category do |f| %>
<%= f.inputs %>
<%= f.buttons %>
<% end %>

<!– views/animals/_form.html.erb –>
<% semantic_form_for @animal do |f| %>
<% f.inputs do %>
<%= f.input :name %>
<%= f.input :born_on, :start_year => 1900 %>
<%= f.input :category, :include_blank => false %>
<%= f.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %>
<% end %>
<%= f.buttons %>
<% end %>
[/html]