code
stringlengths
1
1.73M
language
stringclasses
1 value
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :transactions, d...
Ruby
class Transaction < ActiveRecord::Base STATES = { :WAITING => 1, :DENIED => 2, :APPROVED => 3, :FINISHED => 4, :EXPIRED => 5 } REVERSE_STATES = { 1 => :WAITING, 2 => :DENIED, 3 => :APPROVED, 4 => :FINISHED, 5 => :EXPIRED } ADMIN_PERMISSION = [STATES[:APPROVED], STATES...
Ruby
class Comment < ActiveRecord::Base include ActsAsCommentable::Comment belongs_to :commentable, :polymorphic => true default_scope -> { order('created_at ASC') } # NOTE: install the acts_as_votable plugin if you # want user to vote on the quality of comments. #acts_as_voteable # NOTE: Comments belong ...
Ruby
class TransactionsController < ApplicationController before_filter :admin_check, except: [:show, :index, :new, :create, :all_transactions, :destroy] before_filter :owner_check, only: [:edit, :update, :destroy] helper_method :sort_column, :sort_direction def all_transactions status = params[:status] @t...
Ruby
class SessionsController < ApplicationController before_filter :authenticate_user, :only => [:home, :profile] before_filter :save_login_state, :only => [:login, :login_attempt] def login #Login Form end def login_attempt authorized_user = User.authenticate(params[:username_or_email],params[:login_password]) ...
Ruby
class BooksController < ApplicationController before_filter :admin_check, except: [:index, :show, :rate, :comment] helper_method :sort_column, :sort_direction # GET /books def index @books = Book.paginate(:page => params[:page], per_page: 20, order: "#{params[:sort]} #{params[:d...
Ruby
class CategoriesController < ApplicationController before_filter :admin_check, except: [:index] # GET /categories def index @categories = Category.paginate(:page => params[:page], per_page: 10) respond_to do |format| format.html # index.html.erb end end # GET /categories/new def new ...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery before_filter :authenticate_user! before_filter :set_i18n_locale_from_params protected def set_i18n_locale_from_params if params[:locale] if I18n.available_locales.include?(params[:locale].to_sym) I18n.locale = param...
Ruby
class BookInfosController < ApplicationController # GET /book_infos # GET /book_infos.json helper_method :sort_column, :sort_direction def index @book_infos = BookInfo.order(sort_column + " " + sort_direction).search(params[:search]) #if params[:search] # @book_infos = BookInfo.order(sort_column + ...
Ruby
class UsersController < ApplicationController before_filter :admin_check, only: [:index, :destroy] def index @users = User.paginate( page: params[:page], per_page: 20, ) respond_to do |format| format.html end end def update @user = User.find params[:id] respond_to ...
Ruby
class SearchController < ApplicationController helper_method :sort_column, :sort_direction def search @search_text = params[:search] @results = Book.search_by(@search_text, params[:page], params[:sort], params[:direction]) respond_to do |format| format.html end ...
Ruby
class UserMailer < ActionMailer::Base default from: "admin@library.com" def reminder_email(transaction) @transaction = transaction @user = transaction.user @book = transaction.book mail(to: @user.email, subject: t('.please_return_borrowed_books')) end end
Ruby
# encoding: utf-8 class ImageUploader < CarrierWave::Uploader::Base # Include RMagick or MiniMagick support: include CarrierWave::RMagick # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: include Sprockets::Helpers::RailsHelper include Sprockets::Helpers::IsolatedHelper # Choo...
Ruby
#!/usr/bin/env rake # 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__) Library::Application.load_tasks
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
#!/usr/bin/env rake # 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__) Library::Application.load_tasks
Ruby
source 'https://rubygems.org' gem 'rails', '3.2.6' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' #gem 'pg', '0.14.1' gem 'mysql2' gem 'devise', '2.1.2' gem 'heroku', '2.33.0' gem 'haml', '3.1.7' gem 'jquery-rails', '2.1.3' gem 'will_paginate', '3.0.3' gem 'will_paginate-boots...
Ruby
class CreateRates < ActiveRecord::Migration def self.up create_table :rates do |t| t.belongs_to :rater t.belongs_to :rateable, :polymorphic => true t.integer :stars, :null => false t.string :dimension t.timestamps end add_index :rates, :rater_id add_index :rates, [:r...
Ruby
class AddImageToBooks < ActiveRecord::Migration def change add_column :books, :image, :string end end
Ruby
class CreateTransactions < ActiveRecord::Migration def change create_table :transactions do |t| t.integer :status t.integer :user_id t.integer :book_id t.date :start_date t.date :end_date t.timestamps end end end
Ruby
class AddAdminToUser < ActiveRecord::Migration def up add_column :users, :admin, :boolean change_column_default(:users, :admin, false) end def down remove_column :users, :admin end end
Ruby
class AddDeviseToUsers < ActiveRecord::Migration def self.up change_table(:users) do |t| ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_password_to...
Ruby
class AddNameToBook < ActiveRecord::Migration def change add_column :books, :name, :string end end
Ruby
class CreateBooks < ActiveRecord::Migration def change create_table :books do |t| t.integer :category_id t.string :isbn t.text :description t.integer :total_rate t.integer :copies t.date :publish_date t.string :publisher t.string :author t.string :amazon_link ...
Ruby
class AddRatingAverageToBook < ActiveRecord::Migration def change add_column :books, :rating_average, :decimal, :default => 0, :precision => 6, :scale => 2 end end
Ruby
class CreateAttachments < ActiveRecord::Migration def change create_table :attachments do |t| t.string :path t.integer :book_id t.timestamps end end end
Ruby
class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.string :password t.timestamps end end end
Ruby
class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.string :title, :limit => 50, :default => "" t.text :comment t.references :commentable, :polymorphic => true t.references :user t.string :role, :default => "comments" t.timestamps end...
Ruby
class CreateCategories < ActiveRecord::Migration def change create_table :categories do |t| t.string :name t.text :description t.timestamps end 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' }]) # Mayor.create(name: 'Emanuel...
Ruby
# Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :book do category_id 1 isbn "123456" description "this is a book" total_rate 1 copies 1 publish_date "2012-11-17" publisher "Nguyen An" author "Nguyen An" amazon_link "www.example.co...
Ruby
# Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :category do name "Novel" description "This is a novel" end end
Ruby
# Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :transaction do status 1 end end
Ruby
# Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :user do name "Nguyen Van An" password "password" email "an.nguyen@library.com" end factory :admin, parent: :user do admin true end end
Ruby
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require 'simplecov' SimpleCov.start 'rails' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macr...
Ruby
RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller end
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Library::Application
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
class AddUrlnames < ActiveRecord::Migration # :nodoc: def self.up create_table 'urlnames' do |t| t.column 'nameable_type', :string t.column 'nameable_id', :integer t.column 'name', :string end end def self.down drop_table 'urlnames' end end
Ruby
class CreateMetaDatas < ActiveRecord::Migration def self.up create_table :meta_datas do |t| t.column :content_id, :integer, :null => false t.column :key, :string, :null => false t.column :value, :string, :limit => 255 end add_index :meta_datas, :content_id end def self.down drop...
Ruby
class CreateContents < ActiveRecord::Migration def self.up create_table :contents do |t| t.column :body, :text t.column :content_type, :string end end def self.down drop_table :contents end end
Ruby
class CreateGlobalSettings < ActiveRecord::Migration def self.up create_table :global_settings do |t| t.column :key, :string t.column :value, :string, :default=>"", :null=>false end add_index :global_settings, :key, :unique => true GlobalSettings.reset_column_information GlobalSettings...
Ruby
class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end add_index :sessions, :session_id end def self.down drop_table :sessions end end
Ruby
class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| t.column :title, :string, :null => false, :default => "" t.column :theme_name, :string end end def self.down drop_table :pages end end
Ruby
class CreatePageElements < ActiveRecord::Migration def self.up create_table :page_elements do |t| t.column :page_id, :integer, :null => false t.column :content_id, :integer, :null => false t.column :area_name, :string t.column :position, :integer end add_index :page_elements, :area...
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
#!/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/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/runner'
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/destroy'
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/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/about'
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/console'
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/process/spawner'
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/reaper'
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/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/generate'
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def import_stylesheet (name) "<style type='text/css'>\n@import url('"<< stylesheet_path(name)<< "');\n</style>" end end
Ruby
module ContentsHelper def live_search page<<( remote_function :url => { :action => :live_search },:with => "searchtext") end end
Ruby
module RenderHelper end
Ruby
module PagesHelper def if_ie_tag (content) "\n<!--[if IE]>\n"+content+"\n<![endif]-->\n" end end
Ruby
class Content < ActiveRecord::Base has_many :meta_datas has_many :page_elements, :dependent => :destroy has_many :pages, :through => :page_elements def body_to_html case content_type when "text/textile" if body.blank? "" else textilized = RedCloth.new(body)#, ...
Ruby
class PageElement < ActiveRecord::Base belongs_to :page belongs_to :content # acts_as_list :scope => "area_name = '#{area_name}'" end
Ruby
class GlobalSettings < ActiveRecord::Base def GlobalSettings.[](key_name) find_or_create_by_key key_name.to_s end def self.site_name find_or_create_by_key('site_name').value end def self.site_name=(new_value) find_or_create_by_key('site_name').update_attribute :value, new_value end e...
Ruby
class MetaData < ActiveRecord::Base belongs_to :content end
Ruby
class Page < ActiveRecord::Base attr_reader :page_html has_many :page_elements, :include=>:content, :order=>"area_name, position ASC" do def of_area (area_name) find_all "area_name = '#{area_name}'" end end # returns an array of strings with all the area_names associated to the elements of this pa...
Ruby
class PagesController < ApplicationController layout "pages", :except => :edit # scaffold :page, :suffix => true # scaffold :content, :suffix => true def set_global_settings_site_name begin @setting = GlobalSettings[:site_name] @setting.value = params[:global_settings][:site_name] ...
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 end
Ruby
require 'render_engine' class RenderController < ApplicationController layout false # ecco pronta la regex per beccare i segnalatori dei template: %%[a-z_]+:[a-z_]*(:[a-z_]+)?%% def index show end def show if params[:urlname] @page = Page.find_by_urlname params[:urlname] render :text ...
Ruby
class ContentsController < ApplicationController def write_now @page = Page.find(params[:id]) render :update do |page| page << "goToMenu('write_content_menu');" page.replace_html "widgets", :partial => "write_now" # page.insert_html :bottom, "page_actions", :partial => "write_now" end ...
Ruby
ActionController::Routing::Routes.draw do |map| UJS::routes map.connect '', :controller => "render" map.connect 'admin', :controller => "pages" map.connect 'admin/:controller/:action/:id', :controller => "pages" map.connect ':urlname', :controller => "render", :action=>"show" end
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 =~ /mswin32/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end RAILS...
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
# vim:ts=4:sw=4: # = RedCloth - Textile and Markdown Hybrid for Ruby # # Homepage:: http://whytheluckystiff.net/ruby/redcloth/ # Author:: why the lucky stiff (http://whytheluckystiff.net/) # Copyright:: (cc) 2004 why the lucky stiff (and his puppet organizations.) # License:: BSD # ...
Ruby
require 'rake/gempackagetask' PKG_VERSION = "0.4.0" PKG_NAME = "compages" PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" spec = Gem::Specification.new do |s| s.name = PKG_NAME s.version = PKG_VERSION s.summary = "a small and lean content management & publishing system" s.description = %{Here are the m...
Ruby
require_dependency "page" module RenderEngine protected # def render_meta_tags( template_code ) meta_tag_pattern = /%%content:([a-z]+)%%/ template_code.gsub( meta_tag_pattern ) { || @content.meta_tags.find_by_key $1 } end # overwrite this if you want to restrict access to on...
Ruby
class AddUrlnames < ActiveRecord::Migration # :nodoc: def self.up create_table 'urlnames' do |t| t.column 'nameable_type', :string t.column 'nameable_id', :integer t.column 'name', :string end end def self.down drop_table 'urlnames' end end
Ruby
class CreateMetaDatas < ActiveRecord::Migration def self.up create_table :meta_datas do |t| t.column :content_id, :integer, :null => false t.column :key, :string, :null => false t.column :value, :string, :limit => 255 end add_index :meta_datas, :content_id end def self.down drop...
Ruby
class CreateContents < ActiveRecord::Migration def self.up create_table :contents do |t| t.column :body, :text t.column :content_type, :string end end def self.down drop_table :contents end end
Ruby
class CreateGlobalSettings < ActiveRecord::Migration def self.up create_table :global_settings do |t| t.column :key, :string t.column :value, :string, :default=>"", :null=>false end add_index :global_settings, :key, :unique => true GlobalSettings.reset_column_information GlobalSettings...
Ruby
class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end add_index :sessions, :session_id end def self.down drop_table :sessions end end
Ruby
class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| t.column :title, :string, :null => false, :default => "" t.column :theme_name, :string end end def self.down drop_table :pages end end
Ruby