Running:
| Rails 2.2.2 | ActiveScaffold | CalendarDateSelect | SemanticAttributes |
| Prawnto - try it | RecordSelect | Phusion Passenger™ and Ruby EE |
Change the Language
Id Name Phone Active Signup on Employees Active at
Edit Delete Show Employees
Orders
Info
358 test1

  true

eceijsh eceijsh  
Edit Delete Show Employees
Orders
Info
357 Bob

  false

krpegcr krpegcr 06/24/2009 02:47 PM
Edit Delete Show Employees
Orders
Info
354 hkleiafikub

332-212-2222 false

hkleiafikub hkleiafikub, hkleiafikub hkleiafikub 05/22/2009 11:30 AM

Source

/app/controllers/application.rb

class ApplicationController < ActionController::Base
  include Authorize
  include ExceptionNotifiable

  layout  "admin"
  
  protect_from_forgery :secret => '426afc884e3d819c9f7c7c4e050a5d97'
  
  #password will be hashed before saving in log file
  filter_parameter_logging :password

  protected 

  helper_method :logged_in?, :current_user
  helper_method :permit?, :admin_restrict_to

  def localize
    I18n.locale = session[:lang_code] unless session[:lang_code].nil?
    # Test rescue_action_in_public override
    # raise ActionController::InvalidAuthenticityToken
  end
  
  private
  
  def rescue_action_in_public(exception)
    case exception
      when ActionController::InvalidAuthenticityToken
        # Do nothing, we are getting spurious spaming from some porn sites - trying to get stuff in the DB. Just ignore the filth.
      when *self.class.exceptions_to_treat_as_404
        render_404

      else          
        render_500

        deliverer = self.class.exception_data
        data = case deliverer
          when nil then {}
          when Symbol then send(deliverer)
          when Proc then deliverer.call(self)
        end

        ExceptionNotifier.deliver_exception_notification(exception, self,
          request, data)
    end
  end
  
end

/app/controllers/companies_controller.rb

class CompaniesController < ApplicationController
  append_before_filter :localize

  layout "demo"
    
  ActiveScaffold.set_defaults do |config| 
    config.ignore_columns.add [:created_at, :updated_at]
    config.left_handed = true
  end
  
  active_scaffold :company do |config|
    config.actions.swap :search, :field_search
    config.actions << :customize
    config.actions << :print_list
    config.actions << :export_tool

    config.nested.add_link "Employees", [:employees]
    config.nested.add_link "Orders", [:orders]
    config.nested.add_link "Info", [:employees, :orders]
    
    config.list.sorting = [:id => 'DESC']
    # Any Column#method can be used as a key to the columns_by_key_value hash, for example:
    #   [:phone => {
    #     :description = "(Format: ###-###-####)"
    #   }],
    # We have defined a few synonyms so that you can use the language you prefer:
    #   columns_by_key_value or has_columns
    #   :exclude or :except
    #   :form_ui or :type
    # Because we are using ActiveScaffoldTools - which comes with date, file and boolean bridges -
    #  we do not have to set the type or form_ui for :active_at, :active or :signup_on but we do 
    #  for demo purposes.
    has_columns [
      [:id => {
        :exclude => [:create, :update]
      }],
      [:name => {
        :description => :name_description,
        :inplace_edit => true,
	      :options => {:print_width => "240"},
	      :required => true
      }],
      [:phone => {
        :exclude => [:field_search],
	      :options => {:print_width => "140"},
        :type => :usa_phone,
	      :required => true
      }],
      [:state => {
        :exclude => [:list],
	      :options => {:print_width => "80"},
        :type => :usa_state,
	      :required => true
      }],
      [:active => {
        :form_ui => :checkbox,
        :inplace_edit => true,
	      :options => {:print_width => "80"}
      }],
      [:signup_on => {
        # Force time formatting by uncommenting this line
        # :options => {:showsTime => 1},
        :exclude => [],
        :options => {:field_search => :range}
      }],
      [:comment => {
        :exclude => [:list],
        :options => {:print_width => "440", :rows => 10, :cols => 40},
        :type => :textarea
      }],
      [:employees => {
        :exclude => [:field_search]  
      }],
      [:orders => {
        :exclude => [:field_search, :list]
      }],
      [:active_at => {
        :exclude => [:field_search]
      }]
    ]
  end
    
  def delete_all
    Company.destroy_all
    index
  end
  
  def change_language
    session[:lang_code] = params[:lang_code]
    redirect_to :action => :list
  end

 	protected

  def current_user
    true
  end
  
 	# ===================
  # = Authorize BEGIN =
  # ===================
  
  def create_authorized?
    true
  end
  
  def delete_authorized?
    true
  end
  
  def list_authorized?
    true
  end
  
  def show_authorized?
    true
  end
  
  def update_authorized?
    true
  end
  
  # =================
  # = Authorize END =
  # =================
end

/app/controllers/employees_controller.rb

class EmployeesController < ApplicationController
  # We are not logging in this demo
  # before_filter  :authorize
  
  active_scaffold :employees do |config|
	  has_columns [
      [:first_name => {
        :exclude => []
      }],
      [:last_name => {
        :exclude => [],
	      :required => true
      }],
      [:company => {
        :exclude => []
      }]
	  ]
	end  

 	protected

 	# ===================
  # = Authorize BEGIN =
  # ===================
  
  def create_authorized?
    true
  end
  
  def delete_authorized?
    true
  end
  
  def list_authorized?
    true
  end
  
  def show_authorized?
    true
  end
  
  def update_authorized?
    true
  end
  
  # =================
  # = Authorize END =
  # =================

end

/app/controllers/orders_controller.rb

class OrdersController < ApplicationController
  # We are not logging in this demo
  # before_filter  :authorize
  
  active_scaffold :orders do |config|
	  has_columns [
      [:item_name => {
        :exclude => [],
	      :required => true
      }],
      [:quantity => {
        :exclude => [],
	      :required => true
      }],
      [:company => {
        :exclude => []
      }]
	  ]
	end  

 	protected

 	# ===================
  # = Authorize BEGIN =
  # ===================
  
  def create_authorized?
    true
  end
  
  def delete_authorized?
    true
  end
  
  def list_authorized?
    true
  end
  
  def show_authorized?
    true
  end
  
  def update_authorized?
    true
  end
  
  # =================
  # = Authorize END =
  # =================

end

/app/helpers/companies_helper.rb

module CompaniesHelper
end

/app/models/company.rb

# == Schema Information
# Schema version: 11
#
# Table name: companies
#
#  id              :integer(11)   not null, primary key
#  name            :string(255)   
#  phone           :string(255)   
#  created_at      :datetime      
#  updated_at      :datetime      
#  company_type_id :integer(11)   
#  signup_on       :date          
#  active          :boolean(1)    
#  state           :string(255)   
#  comment         :string(255)   
#  active_at       :datetime      
#
class Company < ActiveRecord::Base
	
	has_many :employees, :dependent => :destroy
	has_many :orders, :dependent => :destroy
	
  
  attribute :name, :is => :required
  attribute :state, :is => :required
	attribute :phone, :is_a => :phone_number

  # ===================
  # = Authorize BEGIN =
  # ===================

  def authorized_for_create?
    true
  end

  def authorized_for_read?
    true
  end
  
  def authorized_for_update?
    true
  end
  
  def authorized_for_delete?
    true
  end

  # =================
  # = Authorize END =
  # =================

end
demo.rhtml is missing

/config/routes.rb

ActionController::Routing::Routes.draw do |map|
  map.connect '', :controller => "as_docs"
  map.connect ':controller/service.wsdl', :action => 'wsdl'
  map.connect ':controller/:action'
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:file_name.:format'
  
  map.resources :companies, :active_scaffold => true, :collection => {:browse => :get}, :member => {:select => :post}

  map.admin '/admin', :controller => "admin/sections"
  
end
report_controller.rb is missing report_helper.rb is missing sample.rfpdf is missing

/db/migrate/20081114153112_create_employees_and_orders.rb

# Create a migration like the following then run:
#   rake db:migrate
# then:
#   script/generate active_scaffold Employee Employees
#   script/generate active_scaffold Order Orders
# then edit the controllers and models a bit and...you are up and running.
#
class CreateEmployeesAndOrders < ActiveRecord::Migration
  def self.up
    create_table :employees, :force => true do |t|
      t.string :first_name
      t.string :last_name
      t.integer :company_id
    end
    create_table :orders, :force => true do |t|
      t.string :item_name
      t.integer :quantity
      t.integer :company_id
    end
  end

  def self.down
    drop_table :orders
    drop_table :employees
  end
end

/config/locales/en-us.yml

"en-us":
  locale_name: "English"
  active_scaffold:
    add:                  "Add"
    add_existing:         "Add Existing"
    are_you_sure:         "Are you sure?"
    cancel:               "Cancel"
    click_to_edit:        "Click to edit"
    close:                "Close"
    create:               "Create"
    create_model:         "Create {{model}}"
    create_another:       "Create Another"
    created_model:        "Created {{model}}"
    create_new:           "Create New"
    customize:            "Customize"
    delete:               "Delete"
    deleted_model:        "Deleted {{model}}"
    delimiter:            "Delimiter"
    download:             "Download"
    edit:                 "Edit"
    export:               "Export"
    filtered:             "(Filtered)"
    found:                "Found"
    hide:                 "Hide"
    live_search:          "Live Search"
    loading…:             "Loading…"
    nested_for_model:     "{{nested_model}} for {{parent_model}}"
    next:                 "Next"
    no_entries:           "No Entries"
    omit_header:          "Omit Header"
    options:              "Options"
    pdf:                  "PDF"
    previous:             "Previous"
    print:                "Print"
    refresh:              "Refresh"
    remove:               "Remove"
    remove_file:          "Remove or Replace file"
    replace_with_new:     "Replace With New"
    revisions_for_model:  "Revisions for {{model}}"
    reset:                "Reset"
    saving…:              "Saving…"
    search:               "Search"
    search_terms:         "Search Terms"
    _select_:             "- select -"
    show:                 "Show"
    show_model:           "Show {{model}}"
    _to_ :                " to "
    update:               "Update"
    update_model:         "Update {{model}}"
    udated_model:         "Updated {{model}}"

    percentage_example:   "Ex. 10%"
    usa_phone_example:    "Ex. 111-333-4444"
    usa_money_example:    "Ex. 1,333"
    usa_zip_example:      "Ex. 88888-3333"
    ssn_example:          "Ex. 555-22-3333"
    
    # error_messages
    internal_error: "Request Failed (code 500, Internal Error)"
    version_inconsistency: "Version inconsistency - this record has been modified since you started editing it."
  date:
    formats:
      # Use the strftime parameters for formats.
      # When no format has been given, it uses default.
      # You can provide other formats here if you like!
      default: "%Y-%m-%d"
      short: "%b %d"
      long: "%B %d, %Y"
      
    day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
    abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
      
    # Don't forget the nil at the beginning; there's no such thing as a 0th month
    month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
    abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
    # Used in date_select and datime_select.
    order: [ :year, :month, :day ]

  time:
    formats:
      default: "%a, %d %b %Y %H:%M:%S %z"
      short: "%d %b %H:%M"
      long: "%B %d, %Y %H:%M"
    am: "am"
    pm: "pm"
      
  # Used in array.to_sentence.
  support:
    array:
      sentence_connector: "and"
      skip_last_comma: false
  number:
    # Used in number_with_delimiter()
    # These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
    format:
      # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
      separator: "."
      # Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
      delimiter: ","
      # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
      precision: 3
      
    # Used in number_to_currency()
    currency:
      format:
        # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
        format: "%u%n"
        unit: "$"
        # These three are to override number.format and are optional
        separator: "."
        delimiter: ","
        precision: 2
        
    # Used in number_to_percentage()
    percentage:
      format:
        # These three are to override number.format and are optional
        # separator: 
        delimiter: ""
        # precision: 
        
    # Used in number_to_precision()
    precision:
      format:
        # These three are to override number.format and are optional
        # separator:
        delimiter: ""
        # precision:
        
    # Used in number_to_human_size()
    human:
      format:
        # These three are to override number.format and are optional
        # separator: 
        delimiter: ""
        precision: 1

  # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
  datetime:
    distance_in_words:
      half_a_minute: "half a minute"
      less_than_x_seconds:
        one:   "less than 1 second"
        other: "less than {{count}} seconds"
      x_seconds:
        one:   "1 second"
        other: "{{count}} seconds"
      less_than_x_minutes:
        one:   "less than a minute"
        other: "less than {{count}} minutes"
      x_minutes:
        one:   "1 minute"
        other: "{{count}} minutes"
      about_x_hours:
        one:   "about 1 hour"
        other: "about {{count}} hours"
      x_days:
        one:   "1 day"
        other: "{{count}} days"
      about_x_months:
        one:   "about 1 month"
        other: "about {{count}} months"
      x_months:
        one:   "1 month"
        other: "{{count}} months"
      about_x_years:
        one:   "about 1 year"
        other: "about {{count}} years"
      over_x_years:
        one:   "over 1 year"
        other: "over {{count}} years"

  activerecord:
    errors:
      template:
        header:
          one:    "1 error prohibited this {{model}} from being saved"
          other:  "{{count}} errors prohibited this {{model}} from being saved"
        # The variable :count is also available
        body: "There were problems with the following fields:"
      # The values :model, :attribute and :value are always available for interpolation
      # The value :count is available when applicable. Can be used for pluralization.
      messages:
        inclusion: "is not included in the list"
        exclusion: "is reserved"
        invalid: "is invalid"
        confirmation: "doesn't match confirmation"
        accepted: "must be accepted"
        empty: "can't be empty"
        blank: "can't be blank"
        too_long: "is too long (maximum is {{count}} characters)"
        too_short: "is too short (minimum is {{count}} characters)"
        wrong_length: "is the wrong length (should be {{count}} characters)"
        taken: "has already been taken"
        not_a_number: "is not a number"
        greater_than: "must be greater than {{count}}"
        greater_than_or_equal_to: "must be greater than or equal to {{count}}"
        equal_to: "must be equal to {{count}}"
        less_than: "must be less than {{count}}"
        less_than_or_equal_to: "must be less than or equal to {{count}}"
        odd: "must be odd"
        even: "must be even"
        # Append your own errors here or at the model/attributes scope.

      # You can define own errors for models or model attributes.
      # The values :model, :attribute and :value are always available for interpolation.
      #
      # For example,
      #   models:
      #     user:
      #       blank: "This is a custom blank message for {{model}}: {{attribute}}"
      #       attributes:
      #         login:
      #           blank: "This is a custom blank message for User login"
      # Will define custom blank validation message for User model and 
      # custom blank validation message for login attribute of User model.
      models:

    # Translate model names. Used in Model.human_name().
    #models:
      # For example,
      #   user: "Dude"
      # will translate User model name to "Dude"

    # Translate model attribute names. Used in Model.human_attribute_name(attribute).
    #attributes:
      # For example,
      #   user:
      #     login: "Handle"
      # will translate User attribute "login" as "Handle"

/config/locales/fr-ca.yml

"fr-ca":
  locale_name: "Francais"
  active_scaffold:
    add:                  "Add"
    add_existing:         "Ajouter des données existantes"
    are_you_sure:         "Est-ce vraiment ce que vous voulez?"
    cancel:               "Annuler"
    click_to_edit:        "Click to edit"
    close:                "Fermer"
    create:               "Créer"
    create_model:         "Créer à {{model}}"
    create_another:       "Créer autre"
    created_model:        "{{model}} créé"
    create_new:           "Créer nouveau"
    customize:            "Customize"
    delete:               "Supprimer"
    deleted_model:        "{{model}} supprimé"
    delimiter:            "Delimiter"
    download:             "Download"
    edit:                 "Modifier"
    export:               "Export"
    filtered:             "(Filtré)"
    found:                "Trouvé"
    hide:                 "Hide"
    live_search:          "Recherche en direct"
    loading…:             "Loading…"
    nested_for_model:     "{{nested_model}} pour {{parent_model}}"
    next:                 "Prochain"
    no_entries:           "Aucune entrée"
    omit_header:          "Omit Header"
    options:              "Options"
    pdf:                  "PDF"
    previous:             "Précédent"
    print:                "Print"
    refresh:              "Refresh"
    remove:               "Enlever"
    remove_file:          "Enlever"
    replace_with_new:     "Replace with New"
    revisions_for_model:  "Remplacer par le nouveau"
    reset:                "Rétablir"
    saving…:              "Saving…"
    search:               "Recherche"
    search_terms:         "Critères de recherche"
    _select_:             " - sélectionner -"
    show:                 "Afficher"
    show_model:           "Afficher {{model}}"
    _to_ :                " to "
    update:               "Mettre à jour"
    update_model:         "Mettre à jour {{model}}"
    udated_model:         "%s mis à jour"

    version_inconsistency: "Incompatibilité des versions – cet enregistrement a été modifié depuis que vous avez commencé à l’éditer."
  record_select:
    n_found:            "{{count}} {{model}} trouvés"
    next:               "Prochain"
    next_count:         "Suivant {{count}}"
    previous:           "Précédent"
    previous_count:     "Précédent {{count}}"

    # AS error messages
  date:
    formats:
      # Use the strftime parameters for formats.
      # When no format has been given, it uses default.
      # You can provide other formats here if you like!
      default: "%d/%m/%Y"
      short: "%e %b"
      long: "%e %B %Y"
      long_ordinal: "%e %B %Y"
      only_day: "%e"

    day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi]
    abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam]

    # Don't forget the nil at the beginning; there's no such thing as a 0th month
    month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre]
    abbr_month_names: [~, jan., fév., mar., avr., mai, juin, juil., août, sept., oct., nov., déc.]
    # Used in date_select and datime_select.
    order: [ :day, :month, :year ]

  time:
    formats:
      default: "%d %B %Y %H:%M"
      time: "%H:%M"
      short: "%d %b %H:%M"
      long: "%A %d %B %Y %H:%M:%S %Z"
      long_ordinal: "%A %d %B %Y %H:%M:%S %Z"
      only_second: "%S"
    am: "am"
    pm: "pm"

  # Used in array.to_sentence.
  support:
    array:
      sentence_connector: "and"
      skip_last_comma: false
  number:
    # Used in number_with_delimiter()
    # These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
    format:
      separator: ','
      delimiter: ' '
      precision: 3

    # Used in number_to_currency()
    currency:
      format:
        # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
        format: "%u%n"
        unit: '€'
        precision: 2
        format: '%n %u'
        separator: "."
        delimiter: ","

    # Used in number_to_percentage()
    percentage:
      format:
        # These three are to override number.format and are optional
        # separator: 
        delimiter: ""
        # precision: 

    # Used in number_to_precision()
    precision:
      format:
        # These three are to override number.format and are optional
        # separator:
        delimiter: ""
        # precision:

    # Used in number_to_human_size()
    human:
      format:
        # These three are to override number.format and are optional
        # separator: 
        delimiter: ""
        precision: 1
    human:
      storage_units: [ Octet, ko, Mo, Go, To ]

  # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
  datetime:
    distance_in_words:
      half_a_minute: "une demi-minute"
      less_than_x_seconds:
        zero:  "moins d'une seconde"
        one:   "moins de 1 seconde"
        other: "moins de {{count}} secondes"
      x_seconds:
        one:   "1 seconde"
        other: "{{count}} secondes"
      less_than_x_minutes:
        zero:  "moins d'une minute"
        one:   "moins de 1 minute"
        other: "moins de {{count}} minutes"
      x_minutes:
        one:   "1 minute"
        other: "{{count}} minutes"
      about_x_hours:
        one:   "environ une heure"
        other: "environ {{count}} heures"
      x_days:
        one:   "1 jour"
        other: "{{count}} jours"
      about_x_months:
        one:   "environ un mois"
        other: "environ {{count}} mois"
      x_months:
        one:   "1 mois"
        other: "{{count}} mois"
      about_x_years:
        one:   "environ un an"
        other: "environ {{count}} ans"
      over_x_years:
        one:   "plus d'un an"
        other: "plus de {{count}} ans"

  activerecord:
    errors:
      template:
        header:
          one:    "1 a empêché ce {{model}} d\'être sauvegardé"
          other:  "{{count}} a interdit ce {{model}} d'être économisé"
        # The variable :count is also available
        body: "Des problèmes sont survenus pour les champs suivants :"
      # The values :model, :attribute and :value are always available for interpolation
      # The value :count is available when applicable. Can be used for pluralization.
      messages:
        inclusion: "n'est pas inclut dans la liste"
        exclusion: "est réservé"
        invalid: "est invalide"
        confirmation: "ne correspond pas à la confirmation"
        accepted: "doit être accepté"
        empty: "ne peut pas être vide"
        blank: "ne peut pas être vierge"
        too_long: "est trop long (%d caractères maximum)"
        too_short: "est trop court(%d caractères minimum)"
        wrong_length: "n'est pas de la bonne longueur (devrait être de %d caractères)"
        taken: "est déjà prit"
        not_a_number: "n'est pas un nombre"
        greater_than: "must be greater than {{count}}"
        greater_than_or_equal_to: "must be greater than or equal to {{count}}"
        equal_to: "must be equal to {{count}}"
        less_than: "must be less than {{count}}"
        less_than_or_equal_to: "must be less than or equal to {{count}}"
        odd: "must be odd"
        even: "must be even"
        
        # Append your own errors here or at the model/attributes scope.

      # You can define own errors for models or model attributes.
      # The values :model, :attribute and :value are always available for interpolation.
      #
      # For example,
      #   models:
      #     user:
      #       blank: "This is a custom blank message for {{model}}: {{attribute}}"
      #       attributes:
      #         login:
      #           blank: "This is a custom blank message for User login"
      # Will define custom blank validation message for User model and 
      # custom blank validation message for login attribute of User model.
      models:

    # Translate model names. Used in Model.human_name().
    #models:
      # For example,
      #   user: "Dude"
      # will translate User model name to "Dude"

    # Translate model attribute names. Used in Model.human_attribute_name(attribute).
    #attributes:
      # For example,
      #   user:
      #     login: "Handle"
      # will translate User attribute "login" as "Handle"

/config/locales/extras/en-us.yml

"en-us":
  activerecord:
    models:
      company: "Customers"
      employee: "Employees"
    attributes:
      company:
        name: "Customer Name"
        name_description: "The Customer's name."

/config/locales/extras/fr-ca.yml

"fr-ca":
  activerecord:
    models:
      company: "Customers"
      employee: "Employees"
    attributes:
      company:
        name: "Customer name"
        name_description: "The customer's name."