code
stringlengths
1
1.73M
language
stringclasses
1 value
# 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.1...
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. # 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. # 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
require 'digest/sha1' require 'yaml' require 'openid' require 'openid/consumer/discovery' require 'openid/extensions/sreg' require 'openid/extensions/pape' require 'openid/extensions/ax' # require "#{Rails.root}/lib/openid_server_system" # require "#{Rails.root}/lib/authenticated_system" # require "#{Rails.root}/lib/y...
Ruby
# Be sure to restart your server when you modify this file. Blog::Application.config.session_store :cookie_store, :key => '_blog_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 gene...
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
Blog::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on ...
Ruby
Blog::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 webserve...
Ruby
Blog::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 sui...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Blog::Application.initialize!
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 you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Blog class Application < Rails::Application # Se...
Ruby
include LoadRoute Blog::Application.routes.draw do # add_page_routes_defined_in_database get "ajax/edit_post" match "edit_post" => "ajax#edit_post", :as => "edit_post" get "ajax/add_comment" match "add_comment" => "ajax#add_comment", :as => "add_comment" get "ajax/del_comment" match "del_comment" => "a...
Ruby
module ApplicationHelper def show_title(title) if title.nil? "Blog Sunflower" else "Blog Sunflower | " + title end end end
Ruby
module AjaxHelper end
Ruby
module UserHelper def signup_error if !@new_user.errors.empty? html = '<div class="alert alert-error fade in">' html += ' <button type="button" class="close" data-dismiss="alert">x</button>' html += ' Errors :' html += ' <ul>' @new_user.errors.each do |e| html += " <li>#{e[1]}</li>...
Ruby
module PostHelper def post_error if !flash[:post_warning].nil? html = '<div class="alert alert-error fade in">' html += ' <button type="button" class="close" data-dismiss="alert">x</button>' html += ' <ul>' flash[:post_warning].each do |e| html += " <li>#{e[1]}</li> " end ...
Ruby
module HomeHelper def set_active(page, current) pageArray = page.split(',') checkHaveIn = false pageArray.each do |page| if page == current return "class='active'" end end if checkHaveIn == false return "" end end def set_sidebar if session[:login].nil? render "user/login" else...
Ruby
class User < ActiveRecord::Base attr_accessor :tmp self.primary_key = :user_id has_many :post has_many :comment validates_confirmation_of :password, :message => 'Password doesn\'t match !', :if => :not_update_profile? validates_presence_of :password_confirmation, :message => 'Re-password is blank !', :if => :not_...
Ruby
class Comment < ActiveRecord::Base self.primary_key = :comment_id belongs_to :user belongs_to :post validates_presence_of :content, :message => 'Post is blank !' validates_length_of :content, :maximum => 250, :message => 'Max.length 250 character !' validates_length_of :content, :minimum => 10, :message => 'Min.l...
Ruby
class Post < ActiveRecord::Base self.primary_key = :post_id belongs_to :user has_many :comment, :dependent => :destroy, :class_name => 'Comment', :order => 'created_at DESC', :limit => 10 validates_presence_of :content, :message => 'Post is blank !' #validates_length_of :content, :maximum => 250, :message => 'Max....
Ruby
class PageRoute < ActiveRecord::Base self.primary_key = :id ActiveRecord::Base.pluralize_table_names = false after_save :reload_routes def route_name name ? name.gsub(/\W+/, ' ').strip.downcase.gsub(/\ +/, '-').gsub('-', '_') : nil end alias_method :as, :route_name def to "#{controller}##{action}" ...
Ruby
class HomeController < ApplicationController def index @page = "home" @all_post = Post.all(:order => "created_at DESC", :limit => 5) @all_post.collect do |p| p.comment.collect do |c| @user_by_comment = User.find(c.user_id) c[:user] = @user_by_comment end end end end
Ruby
class UserController < ApplicationController before_filter :require_login, :only => [:index,:profile,:logout] def index @page = "user" if !params[:id].nil? if params[:id].to_i != @user[:user_id] @anotherUser = User.where(["user_id = ? AND user_type != ?", params[:id], 1]).first if @a...
Ruby
class OpenidController < ApplicationController def index end def start begin oidreq = openid_consumer.begin(params[:openid_identifier]) rescue OpenID::OpenIDError => e redirect_to openid_path, :alert => "Discovery failed for #{params[:openid_identifier]}: #{e}" return end encod...
Ruby
class PostController < ApplicationController def new @page = "new_post" @title = "New Post" if params[:current_path].nil? redirect_to root_path else params[:post][:poster_id] = @user[:user_id] if !params[:ext_content].nil? extContent = params[:ext_content] extImgMedia...
Ruby
module Admin class HomeController < ApplicationController before_filter :require_login def index @page = "AdminManage" @user = User.all end private def require_login if session[:admin].nil? redirect_to root_path end end end end
Ruby
class AjaxController < ApplicationController include HomeHelper include UserHelper skip_before_filter :verify_authenticity_token def edit_post begin @edit_post = Post.find(params[:id]) if !params[:content].nil? @edit_post.update_attributes(:content => params[:content]) end respond_to do |form...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery ActiveRecord::Base.pluralize_table_names = false before_filter :info private def has_login? if session[:login].nil? false else true end end def info if has_login? @user = User.all(:conditions =...
Ruby
require 'oauth2' require 'json' class OauthController < ApplicationController def index begin params[:code] = session[:code] if !session[:code].nil? @consumer=OAuth2::Client.new('64670291c908100628d4e8254dbbb3c8488d79eb97d1045b915c5263caa6ff77', 'cef8bf16840c94bdfc6e0fe2ebc15f400c9588dbaa0fb72762010815...
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.expand_path('../config/application', __FILE__) require 'rake' Blog::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
source 'http://rubygems.org' gem 'rails', '3.1.1' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'oauth2' gem 'pg' gem 'ruby-openid', :require => 'openid' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-...
Ruby
class CreateDatabase < ActiveRecord::Migration def self.up create_table "comment", :primary_key => "comment_id", :force => true do |t| t.integer "post_id" t.text "content" t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" end create_table "post", :primary_key =...
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 =>...
Ruby
module LoadRoute def add_page_routes_defined_in_database PageRoute.all.each do |r| match r.pattern, :to=>r.to, :as=>r.route_name, :via=>r.via end end end
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Blog::Application
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
module UsuariosHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module HilosHelper end
Ruby
module ComentariosHelper end
Ruby
class Comentario < ActiveRecord::Base belongs_to :usuario belongs_to :hilo validates_presence_of :texto end
Ruby
class Hilo < ActiveRecord::Base belongs_to :usuario has_many :comentarios validates_presence_of :texto validates_uniqueness_of :texto end
Ruby
class Usuario < ActiveRecord::Base has_many :hilos has_many :comentarios validates_presence_of :nombre end
Ruby
class ComentariosController < ApplicationController # GET /comentarios # GET /comentarios.xml def index @comentarios = Comentario.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @comentarios } end end # GET /comentarios/1 # GET /comentarios/1.xm...
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 protect_from_forgery # See ActionController::RequestForgeryPr...
Ruby
class HilosController < ApplicationController # GET /hilos # GET /hilos.xml def index @hilos = Hilo.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @hilos } end end # GET /hilos/1 # GET /hilos/1.xml def show @hilo = Hilo.find(params[:id]) ...
Ruby
class UsuariosController < ApplicationController # GET /usuarios # GET /usuarios.xml def index @usuarios = Usuario.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @usuarios } end end # GET /usuarios/1 # GET /usuarios/1.xml def show @usuari...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class ActiveSupport::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 da...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper 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 protect_from_forgery # See ActionController::RequestForgeryPr...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class ActiveSupport::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 da...
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' }]) # Major.create(:name...
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
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
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
# 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
# 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 # Full error reports are disabled and caching is turned on config.action_controller.consider_all_reque...
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. # 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 do debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions 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 attacks. Act...
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 atta...
Ruby
# Be sure to restart your server when you modify this file. # 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. ActiveReco...
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. # 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 # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') ...
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' }]) # Major.create(:name...
Ruby
class CreateComentarios < ActiveRecord::Migration def self.up create_table :comentarios do |t| t.integer :usuario_id t.integer :hilo_id t.text :texto t.integer :estado t.timestamps end end def self.down drop_table :comentarios end end
Ruby
class CreateHilos < ActiveRecord::Migration def self.up create_table :hilos do |t| t.text :texto t.integer :usuario_id t.integer :estado t.timestamps end end def self.down drop_table :hilos end end
Ruby
class CreateUsuarios < ActiveRecord::Migration def self.up create_table :usuarios do |t| t.string :nombre t.timestamps end end def self.down drop_table :usuarios end end
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby