code
stringlengths
1
1.73M
language
stringclasses
1 value
module ResourcesHelper end
Ruby
module AnnouncementsHelper end
Ruby
module MyResourcesHelper end
Ruby
module ProjectsHelper end
Ruby
class Announcement < ActiveRecord::Base belongs_to :project, :foreign_key => :project_id, :class_name => "Project" belongs_to :user, :foreign_key => :user_id, :class_name => "User" validates_presence_of :topic, :content, :kind validates_length_of :topic, :minimum => 4, :maximum => 256, :allow_nil => false, :...
Ruby
class Invitation include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_accessor :email validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i def initialize(attributes = {}) attributes.each do |name, value| send("#...
Ruby
class Project < ActiveRecord::Base has_many :resources has_many :announcements belongs_to :owner, :foreign_key => :owner_id, :class_name => "User" has_many :contributions has_many :users, :through => :contributions # validates associated is crashing app, commenting out for now - Matthew # validates_associate...
Ruby
class User < ActiveRecord::Base has_many :owned_resources, :foreign_key => :user_id, :class_name => "Resource" has_many :announcements has_many :owned_projects, :foreign_key => :owner_id, :class_name => "Project" has_many :contributions has_many :projects, :through => :contributions # validates associated is ...
Ruby
class Ability include CanCan::Ability def initialize(user) if user if user.admin? can :manage, :all else can :manage, User, :id => user.id can :manage, Project, :owner_id => user.id can :manage, Resource do |res| res.user_id == user.id || res.project.owner_i...
Ruby
class Contribution < ActiveRecord::Base belongs_to :user belongs_to :project scope :pending_approval, where(:status => 1) scope :pending_acceptance, where(:status => 2) end
Ruby
class Resource < ActiveRecord::Base belongs_to :project, :foreign_key => :project_id, :class_name => "Project" belongs_to :user, :foreign_key => :user_id, :class_name => "User" has_and_belongs_to_many :users # validates associated is crashing app, commenting out for now - Matthew # validates_associated :users, :o...
Ruby
class AdminUser < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or pr...
Ruby
ActiveAdmin.register Announcement do index do column "User name", :user column "Topic", :topic column "Project", :project column "Type", :kind column "Content", :content column "Create date", :created_at column "Last modified", :updated_at default_actions end form do |f| f.input...
Ruby
ActiveAdmin::Dashboards.build do section "New users" do table_for User.order("created_at desc").limit(3) do column "Full name", :full_name do |user| link_to user.full_name, admin_user_path(user) end column "Nick name", :pref_name column "Email", :email column "Is admin?", :admin end stron...
Ruby
ActiveAdmin.register Project do sidebar "Resources for current project", :only =>:show do table_for Resource.where(:project_id => self.project) do |t| t.column("Resources") { |resource| link_to resource.name, admin_resource_path(resource) } end end sidebar "Contributors for current project", :only =>:show ...
Ruby
ActiveAdmin.register User do scope :administrator index do column "Full name", :full_name column "Nick name", :pref_name column "Email", :email column "Is admin?", :admin? column "Create date", :created_at column "Last modified", :updated_at default_actions end # edit do ...
Ruby
ActiveAdmin.register Resource do index do column "User", :user column "Project", :project column "Resource name", :name column "Version", :version column "Description", :description #column "Location", :location column "Type", :mime column "Created date", :created_at column "Last ...
Ruby
class AdminsController < ApplicationController before_filter :is_logged_in respond_to :html, :xml, :json def change @user = User.find(params[:id]) redirect_to change_user_path(@user), :notice => "Change Admin Mode Here!" end def create @user = User.find(params[:id]) @user.admin = true if...
Ruby
class PasswordResetsController < ApplicationController def new end def create user = User.find_by_email(params[:email]) if user user.send_password_reset redirect_to login_path, :notice => "An email has been sent with reset instructions" else redirect_to login_path, :alert => "You are not regi...
Ruby
class MobileController < ApplicationController def index @user = current_user render :layout => false end end
Ruby
class ProjectsController < ApplicationController before_filter :is_logged_in respond_to :html, :xml, :json def index if(params[:search]) @projects = Project.find(:all, :conditions => ['name LIKE ?', "%#{params[:search]}%"]) else @projects = nil end end def show @project = Pro...
Ruby
class MyProjectsController < ApplicationController before_filter :is_logged_in respond_to :html, :xml, :json def index @projects = current_user.projects.all @projects.concat current_user.owned_projects.all respond_with @projects end end
Ruby
class ResourcesController < ApplicationController before_filter :is_logged_in respond_to :html, :xml, :json before_filter :find_project, :only => [:index, :new, :create] def index @resources = @project.resources.all end def show @resource = Resource.find(params[:id]) end def new @reso...
Ruby
class SessionsController < ApplicationController respond_to :html, :xml, :json def new if current_user redirect_to home_path, :alert => "You are already logged in" else render end end def create user = User.find_by_email(params[:email]) if user && user.authenticate(params[:...
Ruby
class InvitationsController < ApplicationController respond_to :html, :xml, :json before_filter :is_logged_in before_filter :load_project def index if @project.users.include? current_user || @project.owner == current_user redirect_to @project, :alert => "You already contribute to this project" else @p...
Ruby
class ApplicationController < ActionController::Base helper_method :current_user helper_method :home_path def current_user if @current_user.nil? && session[:user_id] @current_user = User.find(session[:user_id]) end @current_user end def is_logged_in if current_user.nil? sess...
Ruby
class MyResourcesController < ApplicationController def index end end
Ruby
class ContributionsController < ApplicationController before_filter :is_logged_in respond_to :html, :xml, :json def create @project = Project.find(params[:project_id]) @user = User.find(params[:user_id]) if Contribution.create(:project => @project, :user => @user) redirect_to current_user, :no...
Ruby
class UsersController < ApplicationController before_filter :is_logged_in, :except => [:new, :create] respond_to :html, :xml, :json def index if(params[:search]) @users = User.find(:all, :conditions => ['full_name LIKE ?', "%#{params[:search]}%"]) else @users = nil end #@user...
Ruby
class AnnouncementsController < ApplicationController before_filter :is_logged_in respond_to :html, :xml, :json before_filter :find_project, :only => [:index, :new, :create] def index @announcements = @project.announcements.all end def show @announcement = Announcement.find(params[:id]) end...
Ruby
class UserMailer < ActionMailer::Base default from: "noreply@projectbox.com" def password_reset(user) @user = user mail :to => user.email, :subject => "ProjectBox Password Reset Request" end def invitation(email, project, user) @project = project @user = user mail :to => email, :subject => "...
Ruby
# encoding: utf-8 class ResourceUploader < CarrierWave::Uploader::Base # Include RMagick or MiniMagick support: # include CarrierWave::RMagick # include CarrierWave::MiniMagick # Choose what kind of storage to use for this uploader: storage :file # storage :fog # Override the directory where uploaded ...
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__) CmsRails::Application.load_tasks
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__) CmsRails::Application.load_tasks
Ruby
source 'http://rubygems.org' gem 'rails', '3.1.1' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3', :group => [:development, :test] gem 'pg', :group => [:production] gem 'activeadmin' gem "activeadmin" gem "meta_search", ">= 1.1.0.pre" gem 'formtastic', '< 2....
Ruby
# A sample Guardfile # More info at https://github.com/guard/guard#readme guard 'rspec', :version => 2 do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } # Rails example watch(%r{^app/(.+)\.rb$}) ...
Ruby
class SpellDescriptionCorrectly < ActiveRecord::Migration def up rename_column :projects, :destription, :description end def down rename_column :projects, :description, :destription end end
Ruby
class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string "full_name" t.string "pref_name" t.string "email" t.boolean "admin" t.string "pass_hash" t.timestamps end end end
Ruby
class RenameUsersProjects < ActiveRecord::Migration def up rename_table :users_projects, :projects_users end def down rename_table :projects_users, :users_projects end end
Ruby
class AddAnnouncementColumn < ActiveRecord::Migration def up add_column :announcements, :project_id, :integer end def down remove_column :announcements, :project_id end end
Ruby
class RenameUserPasswordColumn < ActiveRecord::Migration def up rename_column :users, :pass_hash, :password_digest end def down rename_column :users, :password_digest, :pass_hash end end
Ruby
class CreateProjects < ActiveRecord::Migration def change create_table :projects do |t| t.datetime "started_at" t.datetime "ending_at" t.string "name" t.text "destription" t.integer "owner_id" t.timestamps end end end
Ruby
class MoveAdminNotesToComments < ActiveRecord::Migration def self.up remove_index :admin_notes, [:admin_user_type, :admin_user_id] rename_table :admin_notes, :active_admin_comments rename_column :active_admin_comments, :admin_user_type, :author_type rename_column :active_admin_comments, :admin_user_...
Ruby
class RenameTypeColumns < ActiveRecord::Migration def up rename_column :resources, :type, :mime rename_column :announcements, :type, :kind end def down rename_column :resources, :mime, :type rename_column :announcements, :kind, :type end end
Ruby
class RenameLocationToFile < ActiveRecord::Migration def up rename_column :resources, :location, :file end def down rename_column :resources, :file, :location end end
Ruby
class CreateAdminNotes < ActiveRecord::Migration def self.up create_table :admin_notes do |t| t.string :resource_id, :null => false t.string :resource_type, :null => false t.references :admin_user, :polymorphic => true t.text :body t.timestamps end add_index :admin_notes, [:r...
Ruby
class CreateResources < ActiveRecord::Migration def change create_table :resources do |t| t.integer "user_id" t.integer "project_id" t.string "name" t.integer "version" t.string "description" t.string "location" t.string "type" t.timestamps end end end
Ruby
class AddUserColumns < ActiveRecord::Migration def up add_column :users, :password_reset_token, :string add_column :users, :password_reset_expired_at, :datetime end def down remove_column :users, :password_reset_token remove_column :users, :password_reset_expired_at end end
Ruby
class CreateAnnouncements < ActiveRecord::Migration def change create_table :announcements do |t| t.integer "user_id" t.string "topic" t.text "content" t.string "type" t.timestamps end end end
Ruby
class CreateContributors < ActiveRecord::Migration def up rename_table :projects_users, :contributions change_table :contributions do |t| t.integer :status, :default => 0 end end def down remove_column :contributions, :status rename_table :contributions, :projects_users end end
Ruby
class CreateUsersProjects < ActiveRecord::Migration def change create_table :users_projects do |t| t.integer "user_id" t.integer "project_id" 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
# This file is copied to spec/ when you run 'rails generate rspec:install' require 'rubygems' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rspec' require 'factory_girl' # Requires supporting ruby files with cu...
Ruby
module LogInMacros def stub_logged_in user controller.stubs(:current_user).returns(user) end end
Ruby
require 'factory_girl' FactoryGirl.define do factory :user do full_name 'Matthew Robertson' pref_name 'Matt' sequence(:email){|n| "email#{n}@factory.com" } password 'password' password_confirmation 'password' end factory :announcement do topic "Server Status" content "Schedule of inac...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run CmsRails::Application
Ruby
require 'mkmf' $CPPFLAGS = $CPPFLAGS + " -I../../include" $LDFLAGS = $LDFLAGS + " -L../../" $LIBS = $LIBS + " -lhpdf -lpng -lz" create_makefile 'hpdf'
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- demo.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appea...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- encryption.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- font_example.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright noti...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- arc_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear ...
Ruby
# # << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice ...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- ttfont_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appe...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- text_demo2.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- line_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear...
Ruby
# # << Haru Free PDF Library 2.0.6 >> -- slideshow_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice a...
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../lib/extjs" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a...
Ruby
# include the utils rb file which has extra functionality for the ext theme dir = File.dirname(__FILE__) require File.join(dir, 'lib', 'utils.rb') # register ext4 as a compass framework Compass::Frameworks.register 'ext4', dir
Ruby
module ExtJS4 module SassExtensions module Functions module Utils def parsebox(list, n) assert_type n, :Number if !n.int? raise ArgumentError.new("List index #{n} must be an integer") elsif n.to_i < 1 raise ArgumentError.new("List index #{n} must...
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resource...
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
# 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
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) unless defined?(Rails::Initializer) if File.directory?("#{RAILS_ROOT}/vendor/rails") require "#{RAILS_ROOT}/vendor/rails/railties/lib/init...
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
module RepliesHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def current_user?(user) return true if session[:user_id] == @user.id return false end def current_user user = User.find(session[:user_id]) end def link_to_set_role_of_user(option...
Ruby
module RoleshipsHelper end
Ruby
module UsersHelper end
Ruby
module MoviePicsHelper end
Ruby
module AdminMoviesHelper def show_img(option = {}) if option[:img].nil? return image_tag("/images/little_pic_1", :class => :pic) if option[:thumbnail] == :thumb return image_tag("/images/little_pic_2", :class => :pic) if option[:thumbnail] == :cover else return image_tag(option[:img].publ...
Ruby
module MoviesHelper def show_img(option = {}) if option[:img].nil? return image_tag("/images/little_pic_1", :class => :pic) if option[:thumbnail] == :thumb return image_tag("/images/little_pic_2", :class => :pic) if option[:thumbnail] == :cover else return image_tag(option[:img].public_fi...
Ruby
module SessionHelper end
Ruby
module CinemasHelper end
Ruby
module MovieHousesHelper end
Ruby
module PlaysHelper end
Ruby
module RolesHelper end
Ruby
class Play < ActiveRecord::Base end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_many :roleships, :dependent => :delete_all has_many :roles, :through => :roleships validates_presence_of :name validates_uniqueness_of :name after_save :create_roleship, :set_the_first_user_as_admin cattr_reader :per_page @@per_page =...
Ruby
class Roleship < ActiveRecord::Base belongs_to :user belongs_to :role end
Ruby
class MovieHouse < ActiveRecord::Base validates_presence_of :name, :seat_quantity, :movie_house_state validates_numericality_of :seat_quantity def movie_house_state_judge end protected def validate error.add(:seat_quantity, "should be at least 1") if seat_quantity.nil? || seat_quantity < 1 end...
Ruby
class Reply < ActiveRecord::Base belongs_to :movie validates_presence_of :content cattr_reader :per_page @@per_page = 10 def validate self.name = "fiajgoijdg" if self.name.nil? end end
Ruby
class Role < ActiveRecord::Base has_many :roleships, :dependent => :delete_all has_many :users, :through => :roleships def self.admin admin = find_role 'admin' end def self.guest guest = find_role 'guest' end def self.power_user power_user = find_role 'power_user' end de...
Ruby
class Movie < ActiveRecord::Base SHOW_STATUS = [ [ "on", "on"], [ "off", "off"] ] validates_inclusion_of :show_status, :in => SHOW_STATUS.map{|disp,value|value} has_many :replies has_many :movie_pics has_many :recent_replies, :class_name => "Reply", :order => "created_at DESC", :l...
Ruby
class MoviePic < ActiveRecord::Base belongs_to :movie acts_as_attachment(:content_type => :image, :processor => :Rmagick, :storage => :file_system, :resize_to => '620x480>', :thumbnails => {:cover => '300x390>', :thumb => '70...
Ruby
class MovieHouseSet < ActiveRecord::Base end
Ruby
class Cinema < ActiveRecord::Base validates_presence_of :name, :add, :employees, :movie_house_quantity, :phone, :description validates_numericality_of :employees, :movie_house_quantity protected def validate errors.add(:employees, "should be at least 1") if employees.nil? || employees < 1 errors.add(...
Ruby
class PlaySet < ActiveRecord::Base end
Ruby
class MovieHousesController < ApplicationController layout 'admin_layout' def index @movie_houses = Movie_house.find(:all) end def show @movie_house = Movie_house.find(params[:id]) end def new @movie_house = Movie_house.new end def edit @movie_house = Movie_house.find(params[...
Ruby