code
stringlengths
1
1.73M
language
stringclasses
1 value
module SecuredRecordsHelper def owner_column(record) return '' unless record.owner content = record.owner.to_label content = "<span class='restricted'>#{content}</span>" unless current_login and record.owner == current_login content end end
Ruby
module AliasHelper end
Ruby
module DemoHelper def menu render_partial "/layouts/menu_demo" end end
Ruby
module Nature::DensHelper end
Ruby
module Nature::BearsHelper end
Ruby
module Nature::ParksHelper end
Ruby
module Nature::TrackingDevicesHelper end
Ruby
module Nature::LakesHelper end
Ruby
module RolesHelper include DemoHelper def omnipotent_column(record) record.omnipotent? ? 'yes' : 'no' end def omnipotent_form_column(record, name) check_box :record, :omnipotent, :name => name end end
Ruby
class Address < ActiveRecord::Base belongs_to :addressable, :polymorphic => true def to_label [[self.city, self.state].compact.join(' '), self.zip].compact.join(', ') end end
Ruby
require 'digest/sha1' class Login < ActiveRecord::Base # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login validates_presence_of :password, :if => :password_required? validates_presence_of :password_confirmation, :if => :pas...
Ruby
class TrackingDevice < ActiveRecord::Base belongs_to :taggable, :polymorphic => true end
Ruby
class Permission < ActiveRecord::Base has_and_belongs_to_many :roles def to_label controller end end
Ruby
class SecuredRecord < ActiveRecord::Base belongs_to :owner, :class_name => 'Login', :foreign_key => 'login_id' validates_presence_of :name, :message def authorized_for_destroy? # you can only destroy your own records return true unless existing_record_check? return (current_user and current_user == s...
Ruby
class Lake < ActiveRecord::Base has_and_belongs_to_many :bears end
Ruby
class User < ActiveRecord::Base has_and_belongs_to_many :roles has_many :aliases, :dependent => :destroy has_many :addresses, :as => :addressable validates_presence_of :first_name, :last_name file_column :photo#, :magick => { # :versions => { # :thumb => {:size => "40x40"} # } # } val...
Ruby
class Alias < ActiveRecord::Base belongs_to :user validates_presence_of :name, :user end
Ruby
class Bear < ActiveRecord::Base has_and_belongs_to_many :lakes has_one :den has_one :tracking_device, :as => :taggable end
Ruby
class Den < ActiveRecord::Base belongs_to :park belongs_to :bear end
Ruby
class Role < ActiveRecord::Base has_and_belongs_to_many :users has_and_belongs_to_many :permissions validates_presence_of :name end
Ruby
class Park < ActiveRecord::Base has_many :dens has_many :bears, :through => :dens end
Ruby
class RolesController < DemoController active_scaffold :roles do |config| config.theme = :blue config.actions.exclude :search config.actions << :field_search end end
Ruby
class PermissionsController < DemoController active_scaffold end
Ruby
class AddressesController < ApplicationController active_scaffold end
Ruby
class Nature::LakesController < ApplicationController active_scaffold do |config| [:list, :create, :update, :search].each {|action| config.send(action).columns.exclude :bears} nested.shallow_delete = true config.subform.columns.exclude :meta_title, :meta_keyword config.columns[:meta_title].label = '...
Ruby
class Nature::BearsController < ApplicationController active_scaffold do |c| c.columns[:ticks].calculate = :avg end end
Ruby
class Nature::DensController < ApplicationController active_scaffold :den do |config| end end
Ruby
class Nature::TrackingDevicesController < ApplicationController active_scaffold end
Ruby
class Nature::ParksController < ApplicationController active_scaffold end
Ruby
class SecuredRecordsController < DemoController active_scaffold do |config| config.columns = [:name, :message, :owner] columns[:owner].ui_type = :select end end
Ruby
class AliasController < ApplicationController active_scaffold :alias do |config| config.columns[:name].set_link 'edit', :position => :replace end end
Ruby
class AccountController < ApplicationController def index redirect_to(:action => 'login') end def login return unless request.post? self.current_login = Login.authenticate(params[:login], params[:password]) if logged_in? respond_to do |wants| wants.html { redirect_back_or_...
Ruby
# Filters added to this controller will be run for all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base include AuthenticatedSystem before_filter :generate_menu ActiveScaffold.set_defaults do |config| ...
Ruby
class DemoController < ApplicationController def index redirect_to :controller => 'users' end end
Ruby
class UsersController < DemoController active_scaffold :user do |config| config.columns = [:id, :name, :photo, :first_name, :middle_name, :last_name, :phone_number, :email_address, :login, :password, :roles, :aliases, :addresses] config.columns[:phone_number].description = "(Format: ##...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
class RenameNumBranches < ActiveRecord::Migration def self.up rename_column :trees, :num_branches, :num_leaves end def self.down rename_column :trees, :num_leaves, :num_branches end end
Ruby
class SimplifyNature < ActiveRecord::Migration def self.up %w(branches forests lakes rocks roots shores trees trunks).each { |table| drop_table(table) } create_table :bears, :force => true do |t| t.column :name, :string, :null => false t.column :created_at, :datetime t.column :updated_at, :...
Ruby
class CreateShores < ActiveRecord::Migration def self.up drop_table :forests_lakes create_table :shores do |t| t.column :forest_id, :integer t.column :lake_id, :integer t.column :name, :string end end def self.down drop_table :shores create_table :forests_lakes, :id => false...
Ruby
class ConvertForeignKeysToNull < ActiveRecord::Migration def self.up remove_column :branches, :tree_id add_column :branches, :tree_id, :integer remove_column :rocks, :forest_id add_column :rocks, :forest_id, :integer remove_column :roots, :tree_id add_column :roots, :tree_id, :integer r...
Ruby
class CreateAddresses < ActiveRecord::Migration def self.up create_table :addresses do |t| t.column :city, :string t.column :state, :string t.column :zip, :integer t.column :addressable_id, :integer t.column :addressable_type, :string end end def self.down drop_table :ad...
Ruby
class AddTicksToBears < ActiveRecord::Migration def self.up add_column :bears, :ticks, :integer end def self.down remove_column :bears, :ticks end end
Ruby
class AddBranchesToTrees < ActiveRecord::Migration def self.up add_column :trees, :num_branches, :integer end def self.down remove_column :trees, :num_branches end end
Ruby
class AddPhotoToUsers < ActiveRecord::Migration def self.up add_column :users, :photo, :string end def self.down remove_column :users, :photo, :string end end
Ruby
class InitialSchema < ActiveRecord::Migration def self.up create_table :forests, :force => true do |t| t.column :name, :string t.column :meta_title, :string t.column :meta_keyword, :string t.column :created_on, :datetime t.column :updated_on, :datetime end create_table :rock...
Ruby
class CreateSecurityScenario < ActiveRecord::Migration def self.up create_table "logins", :force => true do |t| t.column :login, :string t.column :email, :string t.column :crypted_password, :string, :limit => 40 t.column :salt, ...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :first_name, :string t.column :middle_name, :string t.column :last_name, :string t.column :phone_number, :string t.column :email_address, :string t.column :login, :string t.column...
Ruby
class RemoveExtraFieldsFromJoinTables < ActiveRecord::Migration def self.up =begin # This migration was causing problems in SQLite3 (it isn't very good at modifying table structures.) # The workaround is to go back and fix migration 002, then just disable this migration. # By disabling this migration, we're assuming ...
Ruby
module AuthenticatedSystem protected # Returns true or false if the user is logged in. # Preloads @current_login with the user model if they're logged in. def logged_in? current_login != :false end # Accesses the current login from the session. def current_login @current_login...
Ruby
desc 'Dump a database to yaml fixtures. Set environment variables DB and DEST to specify the target database and destination path for the fixtures. DB defaults to development and DEST defaults to RAILS_ROOT/ test/fixtures.' task :dump_fixtures => :environment do path = ENV['DEST'] || "#{RAILS_ROOT}/test/fixtures" ...
Ruby
module AuthenticatedTestHelper # Sets the current login in the session from the login fixtures. def login_as(login) @request.session[:login] = login ? logins(login).id : nil end def content_type(type) @request.env['Content-Type'] = type end def accept(accept) @request.env["HTTP_ACCEPT"] = acce...
Ruby
class Menu attr_accessor :label attr_reader :entries def initialize(label = nil) @label = label @entries = [] end end
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/bin/env ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log ...
Ruby
#!/usr/bin/env ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log ...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/bin/env ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log ...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/bin/env ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log ...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
## ## Initialize the environment ## require File.dirname(__FILE__) + '/environment' ## ## Run the install script, too, just to make sure ## require File.dirname(__FILE__) + '/install'
Ruby
require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'rake/rdoctask' require 'find' desc 'Default: run unit tests.' task :default => :test desc 'Test ActiveScaffold.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate docume...
Ruby
require 'exceptions' ## ## Check for dependencies ## version = Rails::VERSION::STRING.split(".") if version[0] < "1" or (version[0] == "1" and version[1] < "2") message = <<-EOM ************************************************************************ Rails 1.2.1 or greater is required. Please remove ActiveSc...
Ruby
## ## Delete public asset files ## require 'fileutils' directory = File.dirname(__FILE__) [ :stylesheets, :javascripts, :images].each do |asset_type| path = File.join(directory, "../../../public/#{asset_type}/active_scaffold") FileUtils.rm_r(path) end
Ruby
# Workaround a problem with script/plugin and http-based repos. # See http://dev.rubyonrails.org/ticket/8189 Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do ## ## Copy over asset files (javascript/css/images) from the plugin directory to public/ ## def copy_files(source_path, destination_path, directory) source, destin...
Ruby
module ActiveScaffold::Config class Core < Base # global level configuration # -------------------------- # provides read/write access to the global Actions DataStructure cattr_reader :actions def self.actions=(val) @@actions = ActiveScaffold::DataStructures::Actions.new(*val) end s...
Ruby
module ActiveScaffold::Config class Delete < Base self.crud_type = :destroy def initialize(core_config) @core = core_config # start with the ActionLink defined globally @link = self.class.link.clone end # global level configuration # -------------------------- # the Actio...
Ruby
module ActiveScaffold::Config class Subform < Base def initialize(core_config) @core = core_config end # global level configuration # -------------------------- # instance-level configuration # ---------------------------- # provides access to the list of columns specifically mean...
Ruby
module ActiveScaffold::Config class Create < Form self.crud_type = :create def initialize(*args) super self.persistent = self.class.persistent end # global level configuration # -------------------------- # the ActionLink for this action def self.link @@link end ...
Ruby
module ActiveScaffold::Config class Nested < Base self.crud_type = :read def initialize(core_config) @core = core_config end # global level configuration # -------------------------- # instance-level configuration # ---------------------------- # Add a nested ActionLink d...
Ruby
module ActiveScaffold::Config class Update < Form self.crud_type = :update # global level configuration # -------------------------- # the ActionLink for this action def self.link @@link end def self.link=(val) @@link = val end @@link = ActiveScaffold::DataStructures::...
Ruby
module ActiveScaffold::Config class FieldSearch < Base self.crud_type = :read def initialize(core_config) @core = core_config @full_text_search = self.class.full_text_search? end # global level configuration # -------------------------- # the ActionLink for this action catt...
Ruby
module ActiveScaffold::Config class Show < Base self.crud_type = :read def initialize(core_config) @core = core_config # start with the ActionLink defined globally @link = self.class.link.clone end # global level configuration # -------------------------- cattr_accessor :l...
Ruby