code
stringlengths
1
1.73M
language
stringclasses
1 value
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'sinatra-activerecord' gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client' group :development do gem 'rake' gem 'sqlite3-ruby' end
Ruby
require 'sinatra.rb' # Sinatra defines #set at the top level as a way to set application configuration set :run, false set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development) require './main' run Sinatra::Application
Ruby
require 'sinatra/activerecord/rake' require './main'
Ruby
class CreateUsers < ActiveRecord::Migration def up create_table :users do |t| t.string :profile_id t.string :email t.string :refresh_token end add_index :users, :profile_id end def down drop_table :users end end
Ruby
# Copyright (C) 2012 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writ...
Ruby
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'sinatra-activerecord' gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client' group :development do gem 'rake' gem 'sqlite3-ruby' end
Ruby
require 'sinatra.rb' # Sinatra defines #set at the top level as a way to set application configuration set :run, false set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development) require './main' run Sinatra::Application
Ruby
require 'sinatra/activerecord/rake' require './main'
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. # 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 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. Balza::Application.config.session_store :cookie_store, :key => '_balza_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 ge...
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
Balza::Application.configure do # Settings specified here will take precedence over those in config/application.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 ...
Ruby
Balza::Application.configure do # Settings specified here will take precedence over those in config/application.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 webserv...
Ruby
Balza::Application.configure do # Settings specified here will take precedence over those in config/application.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 su...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Balza::Application.initialize!
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Balza class Application < Rails::Application # S...
Ruby
Balza::Application.routes.draw do get "registers/index" get "registers/show" get "registers/create" get "registers/edit" get "registers/destroy" get "registers/update" get "registers/new" namespace :admin do resources :students resources :settings resources :banjis r...
Ruby
module ApplicationHelper end
Ruby
module Admin::UsersHelper end
Ruby
module Admin::RegistersHelper end
Ruby
module Admin::BanjisHelper end
Ruby
module Admin::StudentsHelper end
Ruby
module Admin::UnitsHelper end
Ruby
module Admin::GroupsHelper end
Ruby
module Admin::SettingsHelper end
Ruby
module Admin::ProjectsHelper end
Ruby
module Admin::RolesHelper end
Ruby
module AccountsHelper end
Ruby
class Student < ActiveRecord::Base belongs_to :category belongs_to :sex has_and_belongs_to_many :group end
Ruby
class Banji < ActiveRecord::Base belongs_to :setting end
Ruby
class Project < ActiveRecord::Base end
Ruby
require 'digest/sha2' class User < ActiveRecord::Base has_and_belongs_to_many :roles has_many :articles attr_protected :hashed_password, :enabled attr_accessor :password attr_accessor :password_confirmation validates_presence_of :username validates_presence_of :email validates_presence_of :mobile...
Ruby
class Group < ActiveRecord::Base has_and_belongs_to_many :student end
Ruby
class Setting < ActiveRecord::Base has_many :banji end
Ruby
class Role < ActiveRecord::Base has_and_belongs_to_many :users end
Ruby
class Register < ActiveRecord::Base end
Ruby
require "admin/users_controller" class AccountsController < ApplicationController def login @user = User.new(params[:user]) @page_title = "Login" end def authenticate self.logged_in_user = User.authenticate(params[:user][:username], params[:user][:password]) if is_logged_in? redirect_...
Ruby
# encoding: utf-8 class Admin::SettingsController < ApplicationController def index @settings = Setting.find(:all) @page_title = 'Listing settings' end def new @setting = Setting.new @page_title = 'Create new setting' end def create @setting = Setting.new(params[:setting]) if @s...
Ruby
# encoding: utf-8 class Admin::BanjisController < ApplicationController def index @banjis = Banji.find(:all) @page_title = 'Listing banjis' end def create #debugger setting = Setting.where("id = ?", params[:banji][:setting_id]).first period_of_g1 = (setting.created_at.year.to_i + 3).to_s ...
Ruby
class Admin::RolesController < ApplicationController before_filter :check_administrator_role def index @user = User.find(params[:user_id]) @all_roles = Role.find(:all) end def update @user = User.find(params[:user_id]) @role = Role.find(params[:id]) unless @user.has_role?(@role.name) ...
Ruby
class Admin::AppliesController < ApplicationController def index @apply = Apply.find(:all) @page_title = 'Listing applies' end def show end def create @page_title = 'Create new classes' render :action => 'new' end def new @page_title = 'Create new apply' @apply = Apply.new en...
Ruby
# encoding: utf-8 class Admin::GroupsController < ApplicationController def index @groups = Group.find(:all) @page_title = 'Listing groups' end def new @page_title = 'Create new group' @group = Group.new end def create #debugger group_hash = { "j1P" => "初一", "j2P" ...
Ruby
class Admin::ProjectsController < ApplicationController def new @page_title = 'Create new project' @project = Project.new end def create @project = Project.new(params[:project]) if @project.save flash[:notice] = "Project #{@project.name} was successfully created." redirect_to :action ...
Ruby
class Admin::UnitsController < ApplicationController def index end def new end def create end def edit end def destory end def update end end
Ruby
class Admin::RegistersController < ApplicationController def index end def show end def create end def edit end def destroy end def update end def new end end
Ruby
class Admin::StudentsController < ApplicationController def new @page_title = 'Create new student' @student = Student.new end def create @student = Student.new(params[:student]) if @student.save flash[:notice] = "Student #{@student.name} was successfully created." redirect_to :action ...
Ruby
class Admin::UsersController < ApplicationController before_filter :check_administrator_role, :only => [:index, :destroy, :enable] before_filter :login_required, :only => [:edit,:update] def index @users = User.find(:all) @page_title = 'Listing users' end def new ...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery before_filter :setup_session_key include LoginSystem protected def setup_session_key # Pick a unique cookie name to distinguish our session data from others' request.session_options[:session_key] = '_balza' end end
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.expand_path('../config/application', __FILE__) require 'rake' Balza::Application.load_tasks
Ruby
source 'http://rubygems.org' gem 'rake', '0.9.2.2' gem 'rails', '3.0.4' # 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+, ru...
Ruby
class CreateRoles < ActiveRecord::Migration def self.up create_table :roles do |t| t.column :name, :string t.column :description, :text t.timestamps end Role.create(:name => 'Administrator') end def self.down drop_table :roles end end
Ruby
# encoding: utf-8 class CreateRolesUsersJoin < ActiveRecord::Migration def self.up create_table :roles_users, :id => false do |t| t.column :role_id, :integer t.column :user_id, :integer t.timestamps end admin_user = User.create( :username => 'root', :realname => '郑...
Ruby
class CreateGroups < ActiveRecord::Migration def self.up create_table :groups do |t| t.column :name, :string, :null => false t.column :code, :string, :null => false t.column :enabled, :boolean, :default => true, :null => false t.column :description, :text t.timestamps end end ...
Ruby
class CreateRegisters < ActiveRecord::Migration def self.up create_table :registers, :id => false do |t| t.column :student_id, :integer t.column :group_id, :integer t.timestamps end end def self.down drop_table :registers end end
Ruby
class CreateProjects < ActiveRecord::Migration def self.up create_table :projects do |t| t.column :name, :string, :null => false t.column :code, :string, :null => false t.column :enabled, :boolean, :default => true, :null => false t.column :description, :text t.timestamps end e...
Ruby
class CreateSettings < ActiveRecord::Migration def self.up create_table :settings do |t| t.column :name, :string t.column :description, :string t.column :default, :string t.timestamps end end def self.down drop_table :settings end end
Ruby
#utf-8 class CreateUnits < ActiveRecord::Migration def self.up create_table :units do |t| t.column :name, :string t.column :description, :string t.timestamps end end def self.down drop_table :units end end
Ruby
class CreateBanjis < ActiveRecord::Migration def self.up create_table :banjis do |t| t.column :name, :string, :null => false t.column :code, :string, :null => false t.timestamps end end def self.down drop_table :banjis end end
Ruby
class CreateStudents < ActiveRecord::Migration def self.up create_table :students do |t| t.column :name, :string, :null => false t.column :sex_id, :integer t.timestamps end end def self.down drop_table :students end end
Ruby
class AddEditorRole < ActiveRecord::Migration def self.up editor_role = Role.create(:name => 'Editor') admin_user = User.find_by_username('root') admin_user.roles << editor_role end def self.down editor_role = Role.find_by_name('Editor') admin_user = User.find_by_username('root') admin_us...
Ruby
class CreateUnitsUsersJoin < ActiveRecord::Migration def self.up create_table :units_users, :id => false do |t| t.column :unit_id, :integer t.column :user_id, :integer t.timestamps end end def self.down drop_table :units_users end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :username, :string t.column :realname, :string t.column :hashed_password, :string t.column :email, :string t.column :mobile, :string t.column :last_login_at, :datetime t.column :en...
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
module LoginSystem protected def is_logged_in? if session[:user] @logged_in_user = User.find(session[:user]) end end def logged_in_user if is_logged_in? return @logged_in_user end end def logged_in_user=(user) if !user.nil? session[:use...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Balza::Application
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
# define depends jarfiles name libpath = './lib/' api = libpath + 'appengine-api-1.0-sdk-1.3.0.jar' labs = libpath + 'appengine-api-labs-1.3.0.jar' stub = libpath + 'appengine-api-stubs.jar' localruntime = libpath + 'appengine-local-runtime.jar' tools = libpath + 'appengine-tools-api.jar' balmysundaycandycore = libpath...
Ruby
# define depends jarfiles name libpath = './lib/' api = libpath + 'appengine-api-1.0-sdk-1.3.0.jar' labs = libpath + 'appengine-api-labs-1.3.0.jar' stub = libpath + 'appengine-api-stubs.jar' localruntime = libpath + 'appengine-local-runtime.jar' # load? jarfiles require api require labs require stub require localrunti...
Ruby
# define depends jarfiles name libpath = './lib/' api = libpath + 'appengine-api-1.0-sdk-1.3.0.jar' labs = libpath + 'appengine-api-labs-1.3.0.jar' stub = libpath + 'appengine-api-stubs.jar' localruntime = libpath + 'appengine-local-runtime.jar' tools = libpath + 'appengine-tools-api.jar' balmysundaycandycore = libpath...
Ruby
# define depends jarfiles name libpath = './lib/' api = libpath + 'appengine-api-1.0-sdk-1.3.0.jar' labs = libpath + 'appengine-api-labs-1.3.0.jar' stub = libpath + 'appengine-api-stubs.jar' localruntime = libpath + 'appengine-local-runtime.jar' # load? jarfiles require api require labs require stub require localrunti...
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
# 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. ActiveRecord::Base.include_root_in_json = true # Store the full clas...
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
# 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 # Enable threaded mode # config.threadsafe! # Use a different logger for distributed setups # config....
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 # 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 = '2.3...
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 :lancamentos map.resources :naturezas map.resources :arvores map.resources :contas # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller =>...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module NaturezasHelper end
Ruby
module ContasHelper end
Ruby
module LancamentosHelper end
Ruby
module MainHelper end
Ruby
class User < ActiveRecord::Base include Clearance::User end
Ruby
class Natureza < ActiveRecord::Base has_many :lancamentos # Natureza.include_root_in_json = false if Natureza.respond_to?(:include_root_in_json) # acts_as_nested_set def valores_mensais(ano=Time.new.year, meses=[1..12]) Lancamento.sum('valor', :group => 'data', :having => ["natureza_id = ?", self.id]) e...
Ruby
class Lancamento < ActiveRecord::Base acts_as_taggable belongs_to :conta belongs_to :natureza validates_presence_of :conta_id end
Ruby
class Conta < ActiveRecord::Base has_many :lancamentos end
Ruby
class ArvoresController < ApplicationController # GET /arvore # GET /arvore.xml def index(id = params[:node]) @naturezas = Natureza.find_children(id) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @naturezas } format.json { render :json => @naturezas } ...
Ruby
class NaturezasController < ApplicationController # GET /naturezas # GET /naturezas.xml def index @naturezas = Natureza.all() respond_to do |format| format.html # index.html.erb format.xml { render :xml => @naturezas } format.json { render :json => @naturezas } end end # GET /...
Ruby
class LancamentosController < ApplicationController # GET /lancamentos # GET /lancamentos.xml def index @lancamentos = Lancamento.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @lancamentos } end end # GET /lancamentos/1 # GET /lancament...
Ruby
class MainController < ApplicationController layout "main" # before_filter :authenticate, :except => :index def index @lancamento = Lancamento.find(params[:id]) if params[:id] @lancamento ||= Lancamento.new @lancamentos = Lancamento.all(:order=>:data) end end
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 include Clearance::Authentication helper :all # include all helpers, all the time # See ActionController::...
Ruby
class ContasController < ApplicationController # GET /contas # GET /contas.xml def index @contas = Conta.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @contas } end end # GET /contas/1 # GET /contas/1.xml def show @conta = Conta.f...
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/dbconsole'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby