code
stringlengths
1
1.73M
language
stringclasses
1 value
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module AuthHelper end
Ruby
module TagsHelper end
Ruby
module BlogsHelper end
Ruby
class Blogtag < ActiveRecord::Base belongs_to :blog belongs_to :tag end
Ruby
class Tag < ActiveRecord::Base has_many :blogs, :through => :blogtags has_many :blogtags, :dependent => true end
Ruby
# this model expects a certain database layout and its based on the name/login pattern. class User < ActiveRecord::Base has_one :blogs def self.get(openid_url) find_first(["openid_url = ?", openid_url]) end protected validates_uniqueness_of :openid_url, :on => :create validates_presence_of :o...
Ruby
class Blog < ActiveRecord::Base has_many :tags, :through => :blogtags has_many :blogtags, :dependent => true validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix,:message => "should be 'http://xxxxxx'" end
Ruby
require "pathname" require "cgi" # load the openid library begin require "rubygems" require_gem "ruby-openid", ">= 1.0.2" rescue LoadError require "openid" end class AuthController < ApplicationController # process the login request, disover the openid server, and # then redirect. def login openid_...
Ruby
require_dependency "openid_login_system" # Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base layout'standard' # Pick a unique cookie name to distinguish our sess...
Ruby
class TagsController < ApplicationController def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @tag_page...
Ruby
class BlogsController < ApplicationController auto_complete_for :tag, :name auto_complete_for :blog, :name require 'open-uri' require 'md5' require 'iconv' def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :meth...
Ruby
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # ...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end ...
Ruby
# Be sure to restart your web server when you modify this file. # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION ...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
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 'rubygems' require "daemons" require 'yaml' require 'erb' class Hash def with_symbols! self.keys.each{|key| self[key.to_s.to_sym] = self[key] }; self end end options = YAML.load( ERB.new( IO.read( File.dirname(__FILE__) + "/../../config/daemons.yml" )).result).with_symbols!...
Ruby
#!/usr/bin/env ruby #You might want to change this ENV["RAILS_ENV"] ||= "production" require File.dirname(__FILE__) + "/../../config/environment" $running = true; Signal.trap("TERM") do $running = false end #day,week,month,year counter init times=0 #day=0 #week=0 #month=0 #year=0 while($running) do #re calculate...
Ruby
#!/usr/bin/env ruby #You might want to change this ENV["RAILS_ENV"] ||= "production" require File.dirname(__FILE__) + "/../../config/environment" $running = true; Signal.trap("TERM") do $running = false end #day,week,month,year counter init times=0 #day=0 #week=0 #month=0 #year=0 while($running) do #re calculate...
Ruby
#!/usr/bin/env ruby require 'rubygems' require "daemons" require 'yaml' require 'erb' class Hash def with_symbols! self.keys.each{|key| self[key.to_s.to_sym] = self[key] }; self end end options = YAML.load( ERB.new( IO.read( File.dirname(__FILE__) + "/../../config/daemons.yml" )).result).with_symbols!...
Ruby
require_dependency "user" module OpenidLoginSystem protected # overwrite this if you want to restrict access to only a few actions # or if you want to check if the user has the correct rights # example: # # # only allow nonbobs # def authorize?(user) # user.login != "bob" # end def a...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person',...
Ruby
# Be sure to restart your server when you modify this file. # These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveReco...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Act...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying do debug a probl...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.consider_all_reque...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') ...
Ruby
# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? ...
Ruby
ActionController::Routing::Routes.draw do |map| map.resources :incidents map.resources :regles map.resources :machines map.resources :users map.resources :salles # map.resources :password_resets map.login 'login', :controller => 'users', :action => 'login' map.logout 'logout', :controller => 'users', :a...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def authenticated?() not session[:user_id].nil? end def current_user @current_user ||= User.find(session[:user_id]) end def libelle(lib) return lib.gsub("_", " ").capitalize end end
Ruby
module UsersHelper end
Ruby
module SallesHelper end
Ruby
module PasswordResetsHelper end
Ruby
module IncidentsHelper end
Ruby
module MachinesHelper end
Ruby
module ReglesHelper end
Ruby
class Machine < ActiveRecord::Base belongs_to :salle #Permet de créer les associations multiples entre les objets has_many :incidents, :foreign_key => "machineid" #Permet de créer les associations entre les objets validates_presence_of :nommachine ,:ipmachine ,:espacedisquet, :memoiretotale ,:os , :ad...
Ruby
# class UserMailer < ActionMailer::Base # default from: "from@example.com" # def password_reset(user) # @user = user # mail :to => user.email, :subject => "Password Reset" # end # end
Ruby
class Salle < ActiveRecord::Base has_many :machine, :foreign_key => "salleid" #Permet de créer les associations entre les objets validates_presence_of :nomsalle validates_uniqueness_of :nomsalle end
Ruby
class Incident < ActiveRecord::Base belongs_to :machine #Permet de créer les associations multiples entre les objets belongs_to :regle #Permet de créer les associations multiples entre les objets validates_presence_of :typeincident validates_presence_of :machineid, :regleid def self.getstat() nb_inci...
Ruby
class Regle < ActiveRecord::Base has_many :incidents, :foreign_key => "regleid" #Permet de créer les associations entre les objets end
Ruby
class SallesController < ApplicationController # GET /salles # GET /salles.xml def index @salles = Salle.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @salles } end end # GET /salles/1 # GET /salles/1.xml def show @salle = Salle.find(par...
Ruby
# class PasswordResetsController < ApplicationController # def new # end # def create # user = User.find_by_email(params[:email]) # user.send_password_reset if user # redirect_to root_url, :notice => "Email sent with password reset instructions." # end # def edit # @user = User.find_by_password_reset_t...
Ruby
class MachinesController < ApplicationController # GET /machines # GET /machines.xml def index if !params[:salleid].nil? @machines = Machine.find_by_sql("SELECT machines.*, salles.nomsalle FROM machines INNER JOIN salles ON machines.salleid = salles.id and m...
Ruby
class ReglesController < ApplicationController # GET /regles # GET /regles.xml def index @regles = Regle.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @regles } end end # GET /regles/1 # GET /regles/1.xml def show @regle = Regle.find(par...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time # protect_from_forgery # See ActionController::RequestForger...
Ruby
class IncidentsController < ApplicationController before_filter :check_authentification, :only => [:new, :create] before_filter :getmachine, :only => [:new, :create] before_filter :getregle, :only => [:new, :create, :agent] before_filter :getsalle, :only => [:new, :create, :agent] # GET /incidents # GET...
Ruby
class UsersController < ApplicationController def index @user = User.find(:all) respond_to do |format| format.html #index.html end end def show @user = User.find(params[:id]) respond_to do |format| format.html format.xml {render :xml => @user.to_xml} end end def new @us...
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.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
class CreateSalles < ActiveRecord::Migration def self.up create_table :salles do |t| t.string :nomsalle t.timestamps end end def self.down drop_table :salles end end
Ruby
class CreateMachines < ActiveRecord::Migration def self.up create_table :machines do |t| t.string :nommachine t.string :ipmachine t.string :addmac t.string :os t.decimal :memoireutilisee t.decimal :memoiretotale t.decimal :espacedisqueu t.decimal :espacedisquet ...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :login t.string :mdp t.string :type t.timestamps end end def self.down drop_table :users end end
Ruby
class CreateIncidents < ActiveRecord::Migration def self.up create_table :incidents do |t| t.string :typeincident t.string :proprietecomple t.datetime :datedetection t.datetime :dateresolution t.string :etat t.interger :machineid t.interger :regleid t.timestamps ...
Ruby
class CreateRegles < ActiveRecord::Migration def self.up create_table :regles do |t| t.string :descregle t.string :valeurlimite t.string :operationarithme t.timestamps end end def self.down drop_table :regles end end
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Major.create(:name...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class ActiveSupport::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 da...
Ruby
# Steps definitions for security # Fixture instantiation Given /a "(.*)" group/ do |group| Given 'I visit admin/security' And 'I click the "Security Groups" link' And 'I click the "Create" button' And "I put \"#{group}\" in the \"Title\" field" And 'I click the "Save" button' end Given /a user called "(.*)...
Ruby
## FIXTURE GENERATON Given /^the site can be edited by the "([^\"]*)" group$/i do |arg1| pending end Given /^the "([^\"]*)" page can be edited by the "([^\"]*)" group$/i do |arg1, arg2| pending end Given /a "(.*)" page called "(.*)" as a child of "(.*)"/i do |type, title, parent| Given "I click the \"#{paren...
Ruby
# Log in Given /log in as (.*)$/ do |user| Given "I fill out the log in form with user \"#{user}\" and password \"password\"" And 'I see "You\'re logged in as"' end Given /log into the CMS as (.*)/ do |user| Given "I log in as #{user}" And "I visit admin/" And "I load the root node" end Given /log out$/ do ...
Ruby
## ## General rules for the SilverStripe CMS as a whole. They mostly have to do with the LeftAndMain ## interface Given /I click on the "([^\"]*)" tab/ do |tab| Given "I click the \"tab-Root_Content_set_#{tab}\" link" end Given /I wait for a status message/ do Watir::Waiter::wait_until { @browser.p(:id, 'sta...
Ruby
## ## Step definitions for testing the front-end site ## Given /I go to the draft site/ do pending Given 'I click the "viewStageSite" link' # |''element''|//a[@id="viewStageSite"]|''exists''| # |''checking timeout''|@{fast_checking_timeout}| # |''optionally''|''element''|//a[@id="viewStageSite"][@style=""]|''e...
Ruby
# Reset database if $baseURL and $browser then $browser.goto $baseURL + 'dev/tests/endsession' $browser.goto $baseURL + 'dev/tests/startsession?fixture=sapphire/tests/Bare.yml&flush=1' end
Ruby
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
Ruby
require 'webrick' include WEBrick s = HTTPServer.new( :Port => 2010, :DocumentRoot => Dir::pwd ) s.mount('/sh/scripts', WEBrick::HTTPServlet::FileHandler, '../scripts') s.mount('/sh/styles', WEBrick::HTTPServlet::FileHandler, '../styles') trap('INT') { s.stop } s.start
Ruby
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
Ruby
require 'webrick' include WEBrick s = HTTPServer.new( :Port => 2010, :DocumentRoot => Dir::pwd ) s.mount('/sh/scripts', WEBrick::HTTPServlet::FileHandler, '../scripts') s.mount('/sh/styles', WEBrick::HTTPServlet::FileHandler, '../styles') trap('INT') { s.stop } s.start
Ruby
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
Ruby
require 'webrick' include WEBrick s = HTTPServer.new( :Port => 2010, :DocumentRoot => Dir::pwd ) s.mount('/sh/scripts', WEBrick::HTTPServlet::FileHandler, '../scripts') s.mount('/sh/styles', WEBrick::HTTPServlet::FileHandler, '../styles') trap('INT') { s.stop } s.start
Ruby
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
Ruby
require 'webrick' include WEBrick s = HTTPServer.new( :Port => 2010, :DocumentRoot => Dir::pwd ) s.mount('/sh/scripts', WEBrick::HTTPServlet::FileHandler, '../scripts') s.mount('/sh/styles', WEBrick::HTTPServlet::FileHandler, '../styles') trap('INT') { s.stop } s.start
Ruby
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
Ruby
require 'webrick' include WEBrick s = HTTPServer.new( :Port => 2010, :DocumentRoot => Dir::pwd ) s.mount('/sh/scripts', WEBrick::HTTPServlet::FileHandler, '../scripts') s.mount('/sh/styles', WEBrick::HTTPServlet::FileHandler, '../styles') trap('INT') { s.stop } s.start
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
source 'http://rubygems.org' gem 'rails', '3.0.5' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1....
Ruby
module ApplicationHelper end
Ruby
module HomeHelper end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery end
Ruby
class HomeController < ApplicationController def index end end
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', ...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attac...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
# Be sure to restart your server when you modify this file. Blog::Application.config.session_store :cookie_store, :key => '_blog_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails gene...
Ruby