./script/generate scaffold ... |
![]() |
first floor | |||
./script/generate scaffold ... |
![]() |
second floor | |||
... AND SO ON ... | |||||
rake scaffolding:application:from:schema | ![]() |
entire building |
Do you remember algebra?
5 : 10 = 50 : 100
Rails Scaffolding System |
: | ActiveScaffold or Streamlined |
= | AjaxScaffold | : | ActiveScaffold |
![]() |
||||||
Just Evolution! |
Typical use of schema.rb | |||
schema.rb |
![]() |
SQL | |
Scaffolding FROM schema.rb: | first step | ||
schema.rb |
![]() |
Ruby Data Structure | |
Scaffolding FROM schema.rb: | second step | ||
Ruby Data Structure |
![]() |
Migrations, models, controller, test, layout |
Create Rails Application
Install the plugin...
...ActiceScaffold plugin will be installed automagically
Let's configure database connection...
...with your parameters
Let's do SFS rake task: generate schema.rb
Ask when overwriting application controller...
Ask when overwriting routes and helper
Start Rails server...
...and love your application scaffold
Controller contain a complete active_scaffold configuration: you must only delete unnecessary fields
class AccountsController < ApplicationController before_filter :set_title ... active_scaffold :account do |config| ... config.actions.add :live_search ... config.list.columns = [:id, :code, :description, :tipo, :category, :customer_vendor, :link, :gifi, :debit, :credit, :parent_id, :doc_rows, :partners, :tran_rows, :vat_registers] ... end end
Set the root controller
map.root :controller => "accounts"
Layout include style and scripts, title and menu
<title ><%= @title %></title> <%= javascript_include_tag :defaults %> ... <div id="top_nav"><%= render(:partial => '/layouts/top_menu') %></div> ... <%= render(:partial => "/layouts/side_menu") %> ...
We include all direct model associations...
class Account < ActiveRecord::Base has_many :doc_rows, :class_name => 'DocRow', :foreign_key => 'account_id' has_many :partners, :class_name => 'Partner', :foreign_key => 'account_id' has_many :tran_rows, :class_name => 'TranRow', :foreign_key => 'account_id' has_many :vat_registers, :class_name => 'VatRegister', :foreign_key => 'account_id' ... def to_label self.to_s end end
...and all possibles has_many :through associations (dashed)
#has_many :docs, :through => doc_rows #has_many :items, :through => doc_rows #has_many :tax_rates, :through => doc_rows #has_many :accounts, :through => doc_rows #has_many :payments, :through => partners #has_many :banks, :through => partners #has_many :tax_rates, :through => partners #has_many :accounts, :through => partners #has_many :trans, :through => tran_rows #has_many :accounts, :through => tran_rows #has_many :tax_rates, :through => tran_rows #has_many :accounts, :through => vat_registers
The top and side menus content (Streamlined style)
def top_menus ... end def side_menus ... end
and the active_scaffold bindings
def active_scaffold_controller_for(klass) ... end
Q&A Tomaso Minelliminni -at- stat.unipd.it http://www.rails-experience.com |