code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class AddColumnToUsers < ActiveRecord::Migration
def self.up
add_column :users, :openid_url, :string
end
def self.down
remove_column :users, :openid_url
end
end
| Ruby |
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles_users, :id => false, :force => true do |t|
t.column :user_id, :integer
t.column :role_id, :integer
t.column :created_at, :datetime
t.column :updated_at, :datetime
end
create_... | Ruby |
require 'active_record/fixtures'
class LoadGlobalData < ActiveRecord::Migration
def self.up
down
#g_zh_data = File.join(File.dirname(__FILE__), "dev_data" )
#Fixtures.create_fixtures(g_zh_data, "global_zh_data" )
f = Fixtures.new(ViewTranslation.connection, # a database connection
... | Ruby |
class CreateThings < ActiveRecord::Migration
def self.up
create_table :things do |t|
t.column :title,:string
t.column :created_at, :datetime
t.column :updated_at, :datetime
t.column :thingsusers_count, :integer, :default=>0
end
end
def self.down
drop_table :things
end
end
| Ruby |
class AddNickNameSignatureGenderToUsers < ActiveRecord::Migration
def self.up
add_column :users, :nick_name, :string
add_column :users, :signature, :string
add_column :users, :gender, :string
end
def self.down
remove_column :users, :nick_name
remove_column :users, :signature
remove_column... | Ruby |
class CreateProfiles < ActiveRecord::Migration
def self.up
create_table :profiles do |t|
t.column :user_id, :integer
t.column :city, :string
t.column :self_description, :string
t.column :profession, :string
t.column :hobby, :string
t.column :qq, :string
t.column :msn, :st... | Ruby |
class ActsAsTaggableMigration < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.column :name, :string
end
create_table :taggings do |t|
t.column :tag_id, :integer
t.column :taggable_id, :integer
# You should make sure that the column created is... | Ruby |
class AddComments < ActiveRecord::Migration
def self.up
create_table :comments, :force => true do |t|
t.column :title, :string, :limit => 50, :default => ""
t.column :comment, :string, :default => ""
t.column :created_at, :datetime, :null => false
t.column :commentable_id, :integer, :defau... | Ruby |
class CreatePhotoes < ActiveRecord::Migration
def self.up
create_table :photoes do |t|
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.... | Ruby |
class AddCountColumnToUserAndThing < ActiveRecord::Migration
def self.up
add_column :things, :users_count, :integer, :default => 0
add_column :users, :things_count, :integer, :default => 0
end
def self.down
remove_column :things, :users_count
remove_column :users, :things_count
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.column :login, :string
t.column :email, :string
t.column :crypted_password, :string, :limit => 40
t.column :salt, :str... | 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 |
#!d:/ruby/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 impaired... | Ruby |
#!d:/ruby/bin/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 |
#!d:/ruby/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 impaired... | Ruby |
#!d:/ruby/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 impaired... | Ruby |
#!d:/ruby/bin/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 |
#!d:/ruby/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 impaired... | 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/inspector'
| 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/process/inspector'
| 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 fmt_time(str,flag)
if flag=="d"
str.strftime("%Y-%m-%d") unless str.nil?
elsif flag=="s"
str.strftime("%H:%M:%S") unless str.nil?
else
str.strftime("%Y-%m-%d %H:%M:%S") unle... | Ruby |
module IndexHelper
end
| Ruby |
module AuthHelper
end
| Ruby |
module ThingsHelper
end
| Ruby |
module UserHelper
end
| Ruby |
module Admin::TranslateHelper
end
| Ruby |
module AccountHelper
end | Ruby |
module TagHelper
end
| Ruby |
class Thing < ActiveRecord::Base
#To support chinese index
GENERIC_ANALYSIS_REGEX = /([a-zA-Z]|[\xc0-\xdf][\x80-\xbf])+|[0-9]+|[\xe0-\xef][\x80-\xbf][\x80-\xbf]/
GENERIC_ANALYZER = Ferret::Analysis::RegExpAnalyzer.new(GENERIC_ANALYSIS_REGEX, true)
acts_as_ferret({:fields => [ :title, :tags_with_spaces ] }, { :a... | Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
has_many :thingsusers,:dependent =>:destroy
has_many :things, :through => :thingsusers
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :login, :email
validates_presence_of :password, ... | Ruby |
# Defines named roles for users that may be applied to
# objects in a polymorphic fashion. For example, you could create a role
# "moderator" for an instance of a model (i.e., an object), a model class,
# or without any specification at all.
class Role < ActiveRecord::Base
has_and_belongs_to_many :users
belongs_to ... | Ruby |
class Thingsuser < ActiveRecord::Base
belongs_to :user, :counter_cache => true
belongs_to :thing, :counter_cache => true
end
| Ruby |
class TagController < ApplicationController
before_filter :login_required, :only=>:add_tag
def view
@tag = params[:id]
@things = Thing.find_tagged_with @tag
@things.sort
end
def add_tag
@thing = Thing.find params[:id]
@thing.tag_list.clear
for tag in params[:tags].split
@thing.tag... | Ruby |
class UserController < ApplicationController
auto_complete_for :thing,:title
def index
end
def view
@user = User.find_by_login(params[:id])
@user_lists = User.find(:all,:order=>"created_at desc",:limit=>10)
@top_things = Thing.find(:all,:order=>"created_at desc",:limit=>10)
created_times ... | Ruby |
class ThingsController < ApplicationController
before_filter :login_required, :except=>[:view,:search]
def add
return unless request.post?
#判断事件是否存在
thing_tmp = Thing.find_by_title(params[:thing]["title"])
if thing_tmp.nil?
thing_tmp = Thing.create(params[:thing])
end
#用户是否创建过此事
if... | Ruby |
class AccountController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# If you want "remember me" functionality, add this before_filter to Application Controller
before_filter :login_from_cookie
# say something nice, you goof! ... | Ruby |
class TryController < ApplicationController
def ping
@time = Time.now
end
def leftRightLayout
@time = Time.now
@msg = "hello, this is left right layout"
render :layout => 'leftRight'
end
end
| Ruby |
class Admin::TranslateController < ApplicationController
def index
#@view_translations = ViewTranslation.find(:all, :conditions => [ 'built_in IS NULL AND language_id = ?', Locale.language.id ], :order => 'text')
@view_translations = ViewTranslation.find(:all, :conditions => [ 'language_id = 7484'], :orde... | Ruby |
class CommentController < ApplicationController
before_filter :login_required, :only=>[:destroy]
def comment
@commentable_type = params[:comment][:commentable_type]
@asset = eval("#{@commentable_type}.find(params[:id])")
comment = Comment.new(params[:comment])
comment.user_id = session[:user]
... | 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
layout 'scaffold'
# process the login request, disover the openid server, and
# then redirect.
... | 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 AuthenticatedSystem
# Pick a unique cookie name to distinguish our session data from others'
sessio... | Ruby |
class IndexController < ApplicationController
auto_complete_for :thing,:title
def index
# render :layout=>false
@application_description = "Home".t
@things = Thing.find(:all,:limit=>43,:order=>"created_at desc")
@user_lists = User.find(:all,:order=>"created_at DESC",:limit=>10)
@tags = Thi... | 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 =~ /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.
AUTHORIZATION_MIXIN = "object roles"
# 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/rail... | 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 |
module AuthenticatedSystem
protected
# Returns true or false if the user is logged in.
# Preloads @current_user with the user model if they're logged in.
def logged_in?
current_user != :false
end
# Accesses the current user from the session.
def current_user
@current_user ||= ... | Ruby |
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
def content_type(type)
@request.env['Content-Type'] = type
end
def accept(accept)
@request.env["HTTP_ACCEPT"] = accept
en... | 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 |
#!/usr/bin/env ruby
# plot phi colormap and interface position
require 'Tioga/FigureMaker'
class CordPlots
include Math
include Tioga
include FigureConstants
def t
@figure_maker
end
def initialize
@figure_maker = FigureMaker.default
t.def_eval_function { |str| eval(str) }
@phi_range = [0.73, 0.... | 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 |
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end
| Ruby |
class CreateCategories < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :name
t.string :description
t.timestamps
end
end
end
| Ruby |
class CreateOrderDetails < ActiveRecord::Migration
def change
create_table :order_details do |t|
t.integer :order_id
t.integer :product_id
t.integer :qrt
t.timestamps
end
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :product_id
t.string :user_id
t.string :content
t.timestamps
end
end
end
| Ruby |
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
| Ruby |
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.integer :user_id
t.integer :category_id
t.string :name
t.string :imageurl
t.integer :price
t.string :currency
t.text :description
t.timestamps
end
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :address
t.string :role
t.string :phonenum
t.string :password
t.timestamps
end
end
end
| Ruby |
class CreateOrders < ActiveRecord::Migration
def change
create_table :orders do |t|
t.string :name
t.string :email
t.string :address
t.string :phone
t.integer :total
t.integer :state
t.timestamps
end
end
end
| 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 |
#!/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__)
Venshop::Application.load_tasks
| Ruby |
source 'https://rubygems.org'
gem 'rails', '3.2.9'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'json'
gem 'rest-open-uri'
gem 'yaml_db'
gem 'mail'
gem 'sunspot_rails'
gem 'sunspot_solr'
gem 'progress_bar'
# Bundle... | 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 |
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirect... | Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :order_detail do
end
end
| Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :comment, :class => 'Comments' do
end
end
| Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :product, :class => 'Products' do
category_id 1
name "MyString"
imageurl "MyString"
price 1
description "MyString"
end
end
| Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :order do
end
end
| Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :category, :class => 'Categories' do
category_id 1
name "MyString"
end
end
| Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :product_category, :class => 'ProductCategories' do
category_id 1
name "MyString"
end
end
| Ruby |
module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title)
base_title = "Welcome to Coffe 2 Go"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30... | Ruby |
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def isAdmin?
unless signed_in?
return false
end
current_user.role == "admin"
end
def current_user=(user)
... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.