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:

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
# 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
/* formtastic_changes.css */
form.formtastic fieldset ol li p.inline-hints {
  font-style: italic;
  font-size: 11px;
}

<!-- 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 %>

Eingestellt am 26.10.2009 um 09:32

Kategorie: Tutorials

Speichern / Merken / Weitersagen:
  • Print
  • PDF
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • LinkedIn
  • Live
  • MisterWong.DE
  • MisterWong
  • MySpace
  • Netvibes
  • Reddit
  • Technorati
  • Tumblr
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg
  • Slashdot
  • Twitter
  • Twitthis

Kommentare für diesen Artikel wurden geschlossen.