code
stringlengths
1
1.73M
language
stringclasses
1 value
module UsersHelper # Returns the Gravatar (http://gravatar.com/) for the given user. def gravatar_for(user, options = { size: 50 }) gravatar_id = Digest::MD5::hexdigest(user.email.downcase) size = options[:size] gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" image_tag(...
Ruby
module AdminHelper end
Ruby
module CategoriesHelper def categories_menu() @categories = Categories.all end def new_product(count) @newproducts = Products.all @newproducts = @newproducts.sort_by(&:created_at).reverse @newproducts = @newproducts.take(count) end end
Ruby
module HomeHelper end
Ruby
class UserMailer < ActionMailer::Base default :from => "ajhbasdjg@gmail.com" def checkout_email(user, order, id) @user = user @order = order @link_detail = 'http://0.0.0.0:3000/order/'+id @url = "http://localhost:3000" mail(:to => user.email, :subject => 'Order detail') end def se...
Ruby
class OrderDetail < ActiveRecord::Base attr_accessible :order_id, :product_id, :qrt end
Ruby
class Comments < ActiveRecord::Base attr_accessible :user_id, :product_id, :content validates_presence_of :user_id, :message => "please login for this action!" validates :product_id, presence: true validates :content, length: { maximum: 500, minimum: 3} end
Ruby
class Sessions < ActiveRecord::Base end
Ruby
class User < ActiveRecord::Base attr_accessible :name, :email, :address, :phonenum, :role, :password_digest, :password , :password_confirmation, :remember_token has_secure_password before_save { |user| user.email = email.downcase } before_save { |user| user.role = 'user' } VALID_EMAIL_REGEX = /\A[\w+\-.]+@...
Ruby
class Products < ActiveRecord::Base attr_accessible :id, :category_id, :description, :imageurl, :name, :price, :currency, :user_id validates :name, presence: true validates :price, presence: true validates :category_id, presence: true searchable do text :name, :description, :price end def self.uploadfile(...
Ruby
class Categories < ActiveRecord::Base attr_accessible :name, :description validates :name, presence: true validates :description, presence: true end
Ruby
class Order < ActiveRecord::Base attr_accessible :name, :email, :phone, :address, :total, :created_at before_save { |order| order.email = email.downcase } before_save { self.created_at = DateTime.now} VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, ...
Ruby
class SearchController <ApplicationController def index @search = Products.search do fulltext params[':keyword'] end @result = @search.results @key = params[':keyword'] end end
Ruby
class ProductsController <ApplicationController def index redirect_to categories_path end def leave_comment @comment = Comments.new @comment.attributes = params[:comments] if @comment.product_id? @product = Products.find(@comment.product_id) @other_product = Products.where("id !...
Ruby
require 'will_paginate/array' class ApplicationController < ActionController::Base protect_from_forgery before_filter :init_locale include SessionsHelper include CategoriesHelper include ApplicationHelper def switch_locale set_locale(params[:locale]) unless params[:locale].nil? redirect_to request.referer ...
Ruby
require "open-uri" require "json" class GetdataController <ApplicationController def index end def create get_categories end def get_categories url = 'http://shopping.yahooapis.jp/ShoppingWebService/V1/json/categorySearch?appid=dj0zaiZpPXpIMzBsMUQyTk55dSZkPVlXazlZWGxzYjNoWU0yVW1jR285TUEtLSZzPWNvbnN1bWVyc2V...
Ruby
class CategoriesController <ApplicationController def index @newproducts = Products.all.sort_by(&:created_at).reverse @newproducts = @newproducts.paginate page: params[:page], per_page: 12 end def show @cate = Categories.find(params[:id]) @cate_pro = Products.where("category_id = ?", @cate.id) @cate_pro...
Ruby
class CartController <ApplicationController def index @cart = session[:cart] || {} end def addcart pid = params[:pid] product = Products.find(pid) cart = session[:cart] ||= {} cart[pid] = (cart[pid] || 0) + 1 html = session[:cart].count render :text => html end def deletecart pid = params[:pid...
Ruby
class OrderController <ApplicationController def index @order = Order.where("email = ?", current_user.email) @order = @order.paginate page: params[:page], order: 'created_at desc', per_page: 20 end def show @order = Order.find(params[:id]) if (@order.email == current_user.email) @detail = OrderDetail.wh...
Ruby
class HomeController < ApplicationController def home @newproducts = Products.all @newproducts = @newproducts.sort_by(&:created_at).reverse @newproducts = @newproducts.paginate page: params[:page], per_page: 12 end end
Ruby
class UsersController <ApplicationController before_filter :signed_in_user, only: [:index, :edit, :update, :destroy, :following, :followers] before_filter :correct_user, only: [:edit, :update] def index if signed_in? redirect_to edit_user_path(current_user) else redirect_to root_path end end def ...
Ruby
class AdminController < ApplicationController include ApplicationHelper def index unless isAdmin? redirect_to root_path else @category = Categories.new @products = [] @id = 0 if params[:categories] @id = params[:categories]['id'] @products = Products.where(:category_id => params[:categor...
Ruby
class SessionsController < ApplicationController def new end def create user = User.find_by_email(params[:session][:email].downcase) if user && user.authenticate(params[:session][:password]) sign_in user redirect_back_or root_path else flash.now[:error] = 'Invalid email/password' render 'new' e...
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. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
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. Venshop::Application.config.session_store :cookie_store, key: '_venshop_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 g...
Ruby
Venshop::Application.routes.draw do root to: 'home#home' match '/switch_locale', to: 'application#switch_locale' match '/signup', to: 'users#new' match '/signin', to: 'sessions#new' match '/signout', to: 'sessions#destroy', via: :delete match '/email_request', to: 'sessions#email_request' match '/ses...
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 defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Venshop::Application.initialize!
Ruby
Venshop::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action...
Ruby
Venshop::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 web se...
Ruby
Venshop::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
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Venshop::Application
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
; № №№ 0г 0га 0гг 0дм 0кг 0км 0л 0м 0мг 0мм 0см 0т 10-ый 11-ый 12-ый 1г 1га 1гг 1дм 1кг 1км 1л 1м 1мг 1мм 1см 1т 1-ый 2г 2га 2гг 2дм 2кг 2км 2л 2м 2мг 2мм 2-ой 2см 2т 3г 3га 3гг 3дм 3-ий 3кг 3км 3л 3м 3мг 3мм 3см 3т 4г 4га 4гг 4дм 4кг 4км 4л 4м 4мг 4мм 4см 4т 4-ый 5г 5га 5гг 5дм 5кг 5км 5л 5м 5мг 5мм 5см 5т 5-ый 6г 6га...
Ruby
ARToolKitPlus_CamCal_Rev02 640 480 340.353 250.818 766.671 765.529 0.0 0.0 0.0 0.0 0.0 0.0 0
Ruby
class CreateAddresses < ActiveRecord::Migration def self.up create_table :addresses do |t| t.string :name t.string :phone t.string :address t.string :email t.timestamps end end def self.down drop_table :addresses end end
Ruby
class CreateSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.string :session_id, :null => false t.text :data t.timestamps end add_index :sessions, :session_id add_index :sessions, :updated_at end def self.down drop_table :sessions end end
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
#!C:/Apps/InstantRails-2.0-win/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 perfor...
Ruby
#!C:/Apps/InstantRails-2.0-win/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_RO...
Ruby
#!C:/Apps/InstantRails-2.0-win/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 perfor...
Ruby
#!C:/Apps/InstantRails-2.0-win/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 perfor...
Ruby
#!C:/Apps/InstantRails-2.0-win/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_RO...
Ruby
#!C:/Apps/InstantRails-2.0-win/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 perfor...
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' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" 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/console'
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' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" 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/dbconsole'
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/request'
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/performance/request'
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 end
Ruby
module LoginHelper end
Ruby
module MainHelper end
Ruby
class Address < ActiveRecord::Base validates_presence_of :name, :phone end
Ruby
class MainController < ApplicationController def index if (session[:logged_in] == 0) redirect_to(url_for(:controller=>"login", :action=>"index")) end @addresses = Address.find(:all) end def new end def add if (session[:logged_in] == 0) redirect_to(url_for(:controller=...
Ruby
class LoginController < ApplicationController def index end def login session[:logged_in]=1 end def logout session[:logged_in]=0 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 helper :all # include all helpers, all the time # See ActionController::RequestForgeryProtection for details...
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
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! # 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
# 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.2...
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
# 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
# # jQuery File Tree Ruby Connector # # Version 1.01 # # Erik Lax # http://datahack.se # 13 July 2008 # # History # # 1.01 Initial Release # # Output a list of files for jQuery File Tree # #<settings> #root = "/absolute/path/" # or root = File.expand_path(".") #</settings> #<code> require "cgi"...
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
# Fix for FileList class Rake::FileList def exclude_fl(file_list) file_list.to_a.each { |file| self.exclude(file) } end end require 'rake/clean' title = 'couchCaml' task :default => [title] @findlibs = ['unix'] @cmxa = FileList.new('./lib/*.cmxa') # The modules we're working with mods = FileList...
Ruby
platform :ios, '5.0' pod 'JSONKit', '~> 1.4' pod 'Reachability', '~> 3.0.0' pod 'AFNetworking', '1.0'
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