code
stringlengths
1
1.73M
language
stringclasses
1 value
class PhotoController < ApplicationController end
Ruby
class ArticlesController < ApplicationController before_filter :authorize layout "websitearticles" active_scaffold :article do |config| config.label = "Articles" # config.action_links.add 'export_csv', :label => 'Export to Excel', :page => true config.show.link.label = "Show Detail" config.show.lin...
Ruby
class AdmincategoriestController < ApplicationController before_filter :authorize layout "admincategories" active_scaffold :categoryt do |config| config.label = "Category 2" # config.action_links.add 'export_csv', :label => 'Export to Excel', :page => true # config.action_links.add 'trunc_tbl', :labe...
Ruby
class RolesController < ApplicationController before_filter :check_administrator_role layout "adminrole" 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?(@r...
Ruby
class LoginController < ApplicationController before_filter :authorize, :except => [:login,:register] layout "admin" def login session[:user_id] = nil if request.post? if params[:openid_url] puts "enter into openid_url" open_id_authentication(params[:openid_url].strip) ...
Ruby
class Websitearticles3Controller < ApplicationController before_filter :authorize layout "websitearticles1" active_scaffold :article do |config| config.label = "Articles Report" config.actions.exclude :create,:update,:delete,:show config.columns[:category].label = 'Category 1' config....
Ruby
require 'net/http' class WebsitearticlesController < ApplicationController before_filter :authorize layout "websitearticles4" active_scaffold :article do |config| config.label = "Articles" # config.action_links.add 'export_csv', :label => 'Export to Excel', :page => true config.show.link.label = "Show ...
Ruby
class SessionController < ApplicationController def create if open_id?(params[:name]) open_id_authentication(params[:name]) else password_authentication(params[:name], params[:password]) end end protected def password_authentication(name, password) if @curren...
Ruby
require 'net/http' class Articles1Controller < ApplicationController before_filter :authorize before_filter :check_editor_role, :except => [:index, :show] layout "newsarticles" uses_tiny_mce(:options => {:theme => 'advanced', :browsers => %w{msie gecko}, :the...
Ruby
class WebsitesinfoController < ApplicationController def accessdt redirect_to :controller=>'websitesinfs' end end
Ruby
class Websitestasks4Controller < ApplicationController before_filter :authorize layout "page" active_scaffold :websitesinf do |config| config.label = "Websites List" config.show.link.label = "Show Detail" config.show.link.type = :record config.show.link.inline = true config.show.link.position = :after...
Ruby
class UsersController < ApplicationController before_filter :check_administrator_role, :only => [:index, :destroy, :enable] before_filter :login_required, :only => [:edit, :update] layout "adminuser" def index @users = User.find(:all) end def show @user = User.find(params[:id]) end def mph...
Ruby
class ContgrabController < ApplicationController def index end def submit #@images=[] @images=(params[:img].nil?)? []:params[:img].split("=="); end end
Ruby
class SortablelistController < ApplicationController def index end def order @order = params[:list] render :partial => 'list' end end
Ruby
class PhotosController < ApplicationController 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 # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_Adminsite_...
Ruby
class AdminwebsitearticlesController < ApplicationController before_filter :authorize layout "adminwebsitearticles" uses_tiny_mce(:options => {:theme => 'advanced', :browsers => %w{msie gecko}, :theme_advanced_toolbar_location => "top", ...
Ruby
class CopyarticlesController < ApplicationController before_filter :authorize layout "websitearticles3" def mytest4 if params[:mymstest] @messageres = "" @articn = Article.find(params[:article_id]).title @websn = Websitesinf.find(params[:id]).name @messageres="You have successfully copy website: (<b>...
Ruby
class SubtasksdescController < ApplicationController before_filter :authorize layout "websitesinfo" active_scaffold :subtasksdesc do | config | config.label = "Subtasks Information" config.show.link.type = :record config.show.link.inline = true config.show.link.position = :after config.columns = [:...
Ruby
class TasksdescController < ApplicationController before_filter :authorize layout "websitesinfo" active_scaffold :tasksdesc do |config| #config.actions = [:list, :nested] config.label = "Tasks Information" config.columns = [:name,:ecomments1,:last_accessed_at,:last_accessed_user,:last_updat...
Ruby
class Websitestasks3Controller < ApplicationController before_filter :authorize layout "page" active_scaffold :websitesinf do |config| config.label = "Websites List" config.show.link.label = "Show Detail" config.show.link.type = :record config.show.link.inline = true config.show.link.position = :after...
Ruby
class TagsController < ApplicationController before_filter :authorize layout "page" def index @tags = Article.tag_counts(:order => 'name') end def show per_page = 10 @articles = Article.find_tagged_with(params[:id]) @articles_pages, @articles = paginate(Article, {:conditions => ['tags.name...
Ruby
class CategorytsController < ApplicationController before_filter :authorize layout "newscategories" active_scaffold :categoryt do |config| config.label = "Category 2" config.columns = [:name,:websitesinf] config.list.columns = [:name,:websitesinf] end def destroy @cat2obj = Categoryt.fi...
Ruby
class IndexController < ApplicationController # before_filter :authorize, :except => [:index] def index end end
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 =~ /(:?mswin|mingw)/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end ...
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...
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
require 'net/http' # Original credits: http://blog.inquirylabs.com/2006/04/13/simple-uri-validation/ # HTTP Codes: http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPResponse.html class ActiveRecord::Base def self.validates_uri_existence_of(*attr_names) configuration = { :message => "is not v...
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
module LoginSystem protected def is_logged_in? username, password = get_http_auth_data @logged_in_user = User.find(session[:user_id]) if session[:user_id] @logged_in_user = User.authenticate(username, password) if username && password @logged_in_user ? @logged_in_user : false end def logg...
Ruby
# ruby encoding: utf-8 # 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' }]) # May...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... end
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__) QcafeMongodb::Application.load_tasks
Ruby
source "https://rubygems.org" #ruby "1.9.3" # Edit this Gemfile to bundle your application's dependencies. # require 'rubygems' # require 'mongo' source 'http://gemcutter.org' gem "rails" gem "bson_ext" gem "mongo_mapper" # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' # G...
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
module ApplicationHelper def gravatar_url(email, size = 40) gravatar_id = Digest::MD5.hexdigest(email.downcase.strip) "http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}&d=mm" end def nguoi_dung_hien_tai nguoi_dung = nil if session[:nguoi_dung_id].present? # found in session nguo...
Ruby
class NguoiDungMailer < ActionMailer::Base default from: "qcafe.dev@gmail.com" def tao_mat_khau_moi_email(nguoi_dung, url) @nguoi_dung = nguoi_dung @url = url_for( :action => 'tao_mat_khau', :controller => 'nguoi_dung', #:only_path => false, :token => nguoi_dung.mat_khau_moi_token,...
Ruby
class CauHinh include MongoMapper::Document key :ten, String, :presence => true, :length => {:minimum => 4}, :uniqueness => true key :gia_tri, String, :presence => true timestamps! def self.gia_tri(ten, mac_dinh) cau_hinh = CauHinh.find_by_ten(ten) if ...
Ruby
class NguoiDung include MongoMapper::Document #attr_accessible :ten_hien_thi, :email, :mat_khau, :mat_khau_confirmation, :ngon_ngu, :ngay_sinh, :so_dien_thoai, :dia_chi, :vai_tros before_save :ma_hoa_mat_khau key :ten_hien_thi, String, :presence => true, :length => {:minimum => 4, :maxi...
Ruby
class GioHang include MongoMapper::Document before_save :mac_dinh key :dia_chi_nhan_hang, String key :dien_thoai_lien_lac, String key :da_xu_ly, Boolean key :da_xac_nhan, Boolean key :thoi_gian_dat_hang, Time belongs_to :nhan_vien_giao_hang, :class_name => "Ng...
Ruby
class ThongKeGioHang include MongoMapper::Document before_save :mac_dinh key :nam_sinh, Integer key :gioi_tinh, Integer key :so_luong, Integer belongs_to :san_pham timestamps! def mac_dinh end def self.them_gio_hang(gio_hang) nguoi_dung = gio_hang.nguoi_dung if n...
Ruby
require 'mail' module Validators class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) begin parsed = Mail::Address.new(value) rescue Mail::Field::ParseError => e end record.errors.add attribute, "is not valid" unless !parsed.nil? &...
Ruby
class Email include MongoMapper::Document validates :dia_chi, :'validators/email' => true end
Ruby
class DanhMuc include MongoMapper::Document key :loai_danh_muc, String, :presence => true, :length => {:minimum => 4} key :slug, String, :presence => true, :length => {:minimum => 4} many :danh_muc_ngon_ngus many :bai_viets many :san_phams end class DanhM...
Ruby
class SanPham include MongoMapper::Document before_save :xac_dinh_mac_dinh key :slug, String, :presence => true, :length => {:minimum => 4}, :uniqueness => true key :hinh_anh, String, :presence => true, :length => {:minimum => 10} key :dang_kich_hoat, ...
Ruby
class BaiViet include MongoMapper::Document before_save :xac_dinh_mac_dinh key :slug, String, :presence => true, :length => {:minimum => 4}, :uniqueness => true key :ngon_ngu, String, :presence => true, :length => {:minimum => 2} key :tieu_de, Strin...
Ruby
class NguoiDungController < ApplicationController include ApplicationHelper def index end def lich_su_mua_hang if is_khach redirect_to root_url return end @nguoi_dung = nguoi_dung_hien_tai @trang = (params[:page].present? && params[:page].to_i > 1 ? params[:page] : 1).to_i query ...
Ruby
class ApplicationController < ActionController::Base include ApplicationHelper before_filter :set_hostname, :set_locale protect_from_forgery def set_hostname @hostname = "#{request.host_with_port}" end def set_locale locale = "vi" nguoi_dung = nguoi_dung_hien_tai if cookies[:ngon_ngu].pr...
Ruby
class MainController < ApplicationController def index @ngon_ngu = I18n.locale.to_s @blog_ca_phe = BaiViet.where( :dang_kich_hoat => true, :ngon_ngu => @ngon_ngu, :id => {:$in => DanhMuc.find_by_slug('blog_ca_phe').bai_viets.map {|o| o.id}} ).sort(:created_at.desc).first @tin_qcafes...
Ruby
class Admin::NguoiDungController < ApplicationController include ApplicationHelper def index @trang = (params[:page].present? && params[:page].to_i > 1 ? params[:page] : 1).to_i if (params[:cap_nhat].present?) params[:nguoi_dung].each { |k, v| nguoi = NguoiDung.find(k) if (nguoi.pres...
Ruby
class Admin::MainController < ApplicationController def index if params[:commit] # validations if params[:cau_hinh]['email_nhan_gop_y'].present? && !params[:cau_hinh]['email_nhan_gop_y'].blank? email_nhan_gop_y = Email.new(:dia_chi => params[:cau_hinh]['email_nhan_gop_y']) if !email_...
Ruby
class Admin::MediaController < ApplicationController def index end def tao_moi end def cap_nhat end def xoa end end
Ruby
class Admin::GioHangController < ApplicationController include ApplicationHelper def index @trang = (params[:page].present? && params[:page].to_i > 1 ? params[:page] : 1).to_i @ngon_ngu = I18n.locale.to_s if ['da_xu_ly'].include?(params[:loc]) query = GioHang.where(:da_xac_nhan => true, :...
Ruby
class Admin::SanPhamController < ApplicationController include ApplicationHelper def index @trang = (params[:page].present? && params[:page].to_i > 1 ? params[:page] : 1).to_i @danh_muc = DanhMuc.find_by_slug(params[:danh_muc]) @danh_muc_ngon_ngu = @danh_muc.danh_muc_ngon_ngus.select{ |v| v.ngon_ngu ==...
Ruby
class Admin::CauHinhController < ApplicationController def index end end
Ruby
class Admin::BaiVietController < ApplicationController include ApplicationHelper def index @trang = (params[:page].present? && params[:page].to_i > 1 ? params[:page] : 1).to_i @danh_muc = DanhMuc.find_by_slug(params[:danh_muc]) @danh_muc_ngon_ngu = @danh_muc.danh_muc_ngon_ngus.select{ |v| v.ngon_ngu ==...
Ruby
class GioHangController < ApplicationController include ApplicationHelper def index # session[:gio_hang] = nil @ngon_ngu = I18n.locale.to_s if params[:gio_hang_id].present? @gio_hang = GioHang.find(params[:gio_hang_id]) if !@gio_hang.present? redirect_to redirect_url return ...
Ruby
class SanPhamController < ApplicationController include ApplicationHelper def index redirect_url request.url @danh_muc = DanhMuc.find_by_slug(params[:danh_muc_slug]) || not_found @san_pham = SanPham.find_by_slug(params[:san_pham_slug]) if @san_pham.danh_muc.id != @danh_muc.id not_found e...
Ruby
class BaiVietController < ApplicationController def index @danh_muc = DanhMuc.find_by_slug(params[:danh_muc_slug]) || not_found @bai_viet = BaiViet.find_by_slug(params[:bai_viet_slug]) @ngon_ngu = I18n.locale.to_s if (@bai_viet.danh_muc.id != @danh_muc.id) #not_found end @danh_muc_ngon_n...
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
db_config = YAML.load_file("#{Rails.root}/config/mongo.yml") mongo = db_config[Rails.env] MongoMapper.connection = Mongo::Connection.new(mongo['host'], mongo['port']) MongoMapper.database = mongo['database'] if mongo['username'] && mongo['password'] MongoMapper.database.authenticate(mongo['username'], mongo['passwor...
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. QcafeMongodb::Application.config.session_store :cookie_store, key: '_qcafe_mongodb_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 wi...
Ruby
# Câu trả lời từ: http://stackoverflow.com/questions/536619/rails-get-a-teaser-excerpt-for-an-article require 'rexml/parsers/pullparser' class String def truncate_html(len = 30, at_end = nil) p = REXML::Parsers::PullParser.new(self) tags = [] new_len = len results = '' while p.has_next...
Ruby
Recaptcha.configure do |config| config.public_key = '6LdRcd4SAAAAAIJsHJ0qm7tecyU22-MDxDiwxn_b' config.private_key = '6LdRcd4SAAAAAB1JVP6Yyy0ZlqMWHoxJlTg0AfO2 ' end
Ruby
APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml") Phoner::Phone.default_country_code = '84'
Ruby
QcafeMongodb::Application.routes.draw do get "main/ngon_ngu" get "cau_hinh/index" get "nguoi_dung/xoa" get "nguoi_dung/tao_moi" get "media/cap_nhat" get "media/index" get "media/tao_moi" get "media/chi_tiet" get "media/xoa" get "bai_viet/chi_tiet_danh_muc" get "san_pham/chi_tiet_nhom" ...
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__) # Pick the frameworks you want: # require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "sprockets/railtie" require "rails/test_unit/railtie" if defined?(Bundler) # If you precompile...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application QcafeMongodb::Application.initialize!
Ruby
QcafeMongodb::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.a...
Ruby
QcafeMongodb::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 serve...
Ruby
QcafeMongodb::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 suite...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run QcafeMongodb::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__) QcafeMongodb::Application.load_tasks
Ruby
namespace :db do namespace :test do task :prepare do # Stub out for MongoDB end end end
Ruby
require 'csv' namespace :qcafe do desc "Khoi tao khach hang tu 'khach_hang.csv'" task :tao_khach_hang => :environment do csv_text = File.read('khach_hang.csv') csv = CSV.parse(csv_text, :headers => true) csv.each do |row| ten_hien_thi = row[0] email = row[1] so_dien_thoai =...
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
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__) Qcafe::Application.load_tasks
Ruby
source 'https://rubygems.org' gem 'rails', '3.2.1' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'mysql2' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-r...
Ruby
module ApplicationHelper end
Ruby
module GioHangHelper end
Ruby
module Admin::NguoiDungHelper end
Ruby
module Admin::MediaHelper end
Ruby
module Admin::SanPhamHelper end
Ruby
module Admin::BaiVietHelper end
Ruby
module Admin::CauHinhHelper end
Ruby
module Admin::MainHelper end
Ruby
module NguoiDungHelper end
Ruby
module SanPhamHelper end
Ruby
module BaiVietHelper end
Ruby