code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
#!/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/generate'
| 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/about'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.integer :article_id
t.string :author_name
t.string :site_url
t.text :content
t.timestamps
end
end
def self.down
drop_table :comments
end
end
| Ruby |
class AddRoleToUsers < ActiveRecord::Migration
def self.up
add_column :users, :role, :string
end
def self.down
remove_column :users, :role
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username
t.string :email
t.string :persistence_token
t.string :crypted_password
t.string :password_salt
t.timestamps
end
end
def self.down
drop_table :users
end
end
| Ruby |
class CreateAssignments < ActiveRecord::Migration
def self.up
create_table :assignments do |t|
t.integer :user_id
t.integer :role_id
t.timestamps
end
end
def self.down
drop_table :assignments
end
end
| Ruby |
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :roles
end
end
| Ruby |
class AddRolesMaskToUsers < ActiveRecord::Migration
def self.up
add_column :users, :roles_mask, :integer
end
def self.down
remove_column :users, :roles_mask
end
end
| Ruby |
class AddUserToArticles < ActiveRecord::Migration
def self.up
add_column :articles, :user_id, :integer
add_column :comments, :user_id, :integer
end
def self.down
remove_column :comments, :user_id
remove_column :articles, :user_id
end
end
| Ruby |
class CreateArticles < ActiveRecord::Migration
def self.up
create_table :articles do |t|
t.string :name
t.text :content
t.string :author_name
t.timestamps
end
end
def self.down
drop_table :articles
end
end
| Ruby |
# This module is included in your application controller which makes
# several methods available to all controllers and views. Here's a
# common example you might add to your application layout file.
#
# <% if logged_in? %>
# Welcome <%=h current_user.username %>! Not you?
# <%= link_to "Log out", logout_pat... | Ruby |
desc "Setup all for app"
task :setup => ['db:migrate', 'db:fixtures:load']
| Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 Fast... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 Fast... | 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 |
# 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.
# 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 |
# Email settings
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.yourapplication.com",
:port => 25,
:domain => "yourapplication.com",
:authentication => :login,
:user_name => "mail@yourapplication.com",
:password => "yourapplicationpassword"
} | 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 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.
# 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 |
# 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 |
# 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 server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
... | 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 |
dot = '.'
double_dot = ':'
slash = '/'
p_nam = 'post'
p_name = p_nam + 's'
p_name_show = 'show'
p_name_edit = 'edit'
p_name_dest = 'destroy'
_controller = 'controller'
_controller_ = double_dot + _controller
type_action_ = slash + _controller_
type_action = type_action_ + slash
_action = 'action'
_action_ = doubl... | Ruby |
atom_feed do |feed|
feed.title("Nami's blog")
feed.updated(@posts.first.created_at)
@posts.each do |post|
feed.entry(post) do |entry|
entry.title(post.title)
entry.content(post.body, :type => 'html')
entry.author { |author| author.name("Nami") }
end
end
end | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def jQexternal_link_to name, options = {}, html_options = nil, *parameters_for_method_reference
(html_options ||= {}).merge!({:class => "external"})
link_to name, options, html_options, *parameters_for_me... | Ruby |
module UsersHelper
end
| Ruby |
module SessionsHelper
end
| Ruby |
module PostsHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
class Comment < ActiveRecord::Base
validates_presence_of :body
belongs_to :post
belongs_to :user
end | Ruby |
class Post < ActiveRecord::Base
validates_presence_of :body, :title #1 seule ligne !
validates_uniqueness_of :title
validates_length_of :title, :minimum => 3
validates_length_of :body, :minimum => 10
has_many :comments
belongs_to :user
def self.search(search, page)
paginate :per_page => 5, :page => page,
... | Ruby |
class PostsController < ApplicationController
before_filter :authenticate, :except => [:index, :show]
# GET /posts
# GET /posts.xml
def index
@posts = Post.paginate(:per_page => 3, :page => params[:page], :order => 'created_at DESC')
@posts = @posts.reverse
respond_to do |format|
format.html # index.html... | Ruby |
class CommentsController < ApplicationController
before_filter :authenticate, :only => [:destroy]
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(params[:comment])
respond_to do |format|
format.html { redirect_to @post }
format.js
end
end
def destroy
@comment = ... | Ruby |
class SessionsController < ApplicationController
def new
end
def create
user = User.authenticate(params[:login], params[:password])
if user
session[:user_id] = user.id
flash[:notice] = "Logged in successfully."
redirect_to_target_or_default(root_url)
else
flash.now[:error] =... | 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::RequestForgeryProt... | Ruby |
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
session[:user_id] = @user.id
flash[:notice] = "Thank you for signing up! You are now logged in."
redirect_to root_url
else
render :action =... | 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 |
#!/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/console'
| 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/performance/benchmarker'
| 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/profiler'
| 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__)
$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/runner'
| 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/generate'
| 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/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/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/plugin'
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.integer :post_id
t.text :body
t.timestamps
end
end
def self.down
drop_table :comments
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username
t.string :email
t.string :password_hash
t.string :password_salt
t.timestamps
end
end
def self.down
drop_table :users
end
end
| Ruby |
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
def self.down
drop_table :posts
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' }])
# Major.create(:name... | Ruby |
# This module is included in your application controller which makes
# several methods available to all controllers and views. Here's a
# common example you might add to your application layout file.
#
# <% if logged_in? %>
# Welcome <%=h current_user.username %>! Not you?
# <%= link_to "Log out", logout_pat... | 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 |
# 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 |
require 'machinist/active_record'
require 'sham'
require 'faker'
Dir["#{RAILS_ROOT}/_test/blueprints/*.rb"].each { |f| require f } | 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 |
# A Site key gives additional protection against a dictionary attack if your
# DB is ever compromised. With no site key, we store
# DB_password = hash(user_password, DB_user_salt)
# If your database were to be compromised you'd be vulnerable to a dictionary
# attack on all your stupid users' passwords. With a site... | 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 bet... | Ruby |
# Be sure to restart your server when you modify this file
#require "smtp_tls"
# 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'
ENV['RAILS_RELATIVE_URL_ROOT']= "/aizuppo"
# Specifies gem version of Rails ... | 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 |
ActionController::Routing::Routes.draw do |map|
map.activate '/activate/:activation_code', :activation_code => '', :controller => 'users', :action => 'activate'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.register '/re... | Ruby |
User.blueprint do
login { Faker::Internet.user_name }
password 'testing'
password_confirmation { password }
email { Faker::Internet.email }
activation_code { nil }
activated_at { 5.days.ago }
state { 'active' }
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 da... | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def hbr(target)
target = html_escape(target)
target.gsub(/\r\n|\r|\n/, "<br />")
end
end
| Ruby |
module UsersHelper
#
# Use this to wrap view elements that the user can't access.
# !! Note: this is an *interface*, not *security* feature !!
# You need to do all access control at the controller level.
#
# Example:
# <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> ... | Ruby |
module SessionsHelper
end | Ruby |
module NeedsHelper
end
| Ruby |
module TopsHelper
end
| Ruby |
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
@body[:url] = "http://YOURSITE/activate/#{user.activation_code}"
end
def activation(user)
setup_email(user)
@subject += 'Your account has been ac... | Ruby |
class Top < ActiveRecord::Base
end
| Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
include Authorization::StatefulRoles
validates_presence_of :login
validates_length_of :login, :within => 3..40
validates_uniqueness_of :logi... | Ruby |
class Need < ActiveRecord::Base
end
| Ruby |
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserMailer.deliver_signup_notification(user)
end
def after_save(user)
UserMailer.deliver_activation(user) if user.recently_activated?
end
end
| Ruby |
class NeedsController < ApplicationController
# GET /needs
# GET /needs.xml
def index
@needs = Need.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @needs }
end
end
def attend
@nid=params[:id]
@need=Need.find(params[:id])
#@need... | Ruby |
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.html.erb
def new
end
def create
logout_keeping_session!
user = Us... | Ruby |
class TopsController < ApplicationController
# GET /tops
# GET /tops.xml
def index
@tops = Top.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @tops }
end
end
# GET /tops/1
# GET /tops/1.xml
def show
@top = Top.find(params[:id])
... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.