code
stringlengths
1
1.73M
language
stringclasses
1 value
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 end # Accesses the current user from the session. # Future calls avoid the database because nil is not ...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user_id] = user ? (user.is_a?(User) ? user.id : users(user).id) : nil end def authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentic...
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): # Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # i...
Ruby
# Add the emails which should receive exception notifications below. ie: %W(admin1@yoursite.com admin2@yoursite.com) ExceptionNotifier.sender_address = %("Name Error <error@appname.url>") ExceptionNotifier.exception_recipients = %W() ExceptionNotifier.email_prefix = "[App name Exception] "
Ruby
require 'avatar' require 'avatar/source/file_column_source' require 'avatar/source/source_chain' require 'avatar/source/static_url_source' require 'avatar/source/wrapper/rails_asset_source_wrapper' require 'avatar/source/wrapper/string_substitution_source_wrapper' require 'sized_gravatar_source' # order: # 1. FileCol...
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
FileColumn::ClassMethods::DEFAULT_OPTIONS[:root_path] = File.join(RAILS_ROOT, "public", 'system') FileColumn::ClassMethods::DEFAULT_OPTIONS[:web_root] = 'system/'
Ruby
# Change globals to match the proper value for your site DELETE_CONFIRM = "Are you sure you want to delete?\nThis can not be undone." SEARCH_LIMIT = 25 SITE_NAME = 'Lovd By Less' SITE = RAILS_ENV == 'production' ? 'lovdbyless.com' : 'localhost:3000' MAILER_TO_ADDRESS = 'info@#{SITE}' MAILER_FROM_ADDRESS = 'The Lovd ...
Ruby
# ====================== # = Flickr Integration = # ====================== require 'flickr' FLICKR_KEY = '' FLICKR_SECRET = '' FLICKR_CACHE = "#{RAILS_ROOT}/config/flickr.cache"
Ruby
require 'rubygems' require 'ostruct'
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
# require "ruby-debug" # 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...
Ruby
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| # Cookie sessions (limit = 4K) # WARNING: You MUST generate a new secret (use "rake secret...
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.namespace :admin do |a| a.resources :users, :collection => {:search => :post} end map.resources :profiles, :member=>{:delete_icon=>:post}, :collection=>{:search=>:get}, :has_many=>[:friends, :blogs, :photos, :comments, :feed_items, :messages] map....
Ruby
xml = xml_instance unless xml_instance.nil? xml.item do topic = feed_item.item xml.title "#{topic.owner} posted #{topic.title} in #{sanitize(textilize(topic.forum.name))}" xml.description sanitize(textilize(topic.posts.first.body)) xml.author "#{topic.owner.email} (#{topic.owner.f})" xml.pubDate topic.updated_...
Ruby
xml = xml_instance unless xml_instance.nil? xml.item do f = feed_item.item xml.title "#{f.inviter.f} is now a #{f.description f.inviter} of #{f.invited.f}" xml.description "#{f.inviter.f}'s network in #{SITE_NAME} has been updated." xml.author "#{f.invited.email} (#{f.invited.f})" xml.pubDate feed_item.create...
Ruby
xml = xml_instance unless xml_instance.nil? xml.item do b = feed_item.item xml.title "#{b.profile.f} blogged #{time_ago_in_words b.created_at} #{b.title}" xml.description sanitize(textilize(b.body)) xml.author "#{b.profile.email} (#{b.profile.f})" xml.pubDate b.updated_at xml.link profile_blog_url(b.profile...
Ruby
c ||= comment c ||= feed_item.item xml = xml_instance unless xml_instance.nil? xml.item do xml.title commentable_text(c, false) xml.link profile_feed_item_url(@profile, c) xml.guid profile_feed_item_url(@profile, c) xml.description sanitize(textilize(c.comment)) xml.author "#{c.profile.email} (#{c.profile.f}...
Ruby
xml = xml_instance unless xml_instance.nil? xml.item do p = feed_item.item xml.title "#{p.profile.f} uploaded a photo" xml.description p.caption.blank? ? 'No caption provided' : sanitize(textilize(p.caption)) xml.author "#{p.profile.email} (#{p.profile.f})" xml.pubDate p.updated_at xml.link profile_photo_ur...
Ruby
xml.instruct! :xml, :version=>"1.0" xml.rss(:version=>"2.0") do xml.channel do xml.title "#{SITE_NAME} Latest Comments Feed" xml.link SITE xml.description "All the action for #{SITE_NAME}" xml.language 'en-us' recent_comments.each do |c| xml.item do xml.title commentable_text(c, fal...
Ruby
xml.instruct! :xml, :version=>"1.0" xml.rss(:version=>"2.0") do xml.channel do xml.title "#{SITE_NAME} Newest Member Feed" xml.link SITE xml.description "This feed will quickly show who has recently signed up for #{SITE_NAME}" xml.language 'en-us' new_members.each do |newest_member| xml.ite...
Ruby
#locals comments ||= @comments parent ||= @parent profile ||= @profile xml.instruct! :xml, :version=>"1.0" xml.rss(:version=>"2.0"){ xml.channel do xml.title "Wall to wall with #{profile.f}" xml.link SITE xml.description "Wall to wall with #{profile.f} on #{SITE_NAME}" xml.language 'en-us' comm...
Ruby
xml.instruct! :xml, :version=>"1.0" xml.rss(:version=>"2.0"){ xml.channel do xml.title "#{SITE_NAME} Activity Feed" xml.link SITE xml.description "This feed will quickly show you what has recently happened on #{SITE_NAME} without having to login." xml.language 'en-us' @feed_items.each do |feed_ite...
Ruby
xml.instruct! :xml, :version=>"1.0" xml.rss(:version=>"2.0") do xml.channel do xml.title "#{@profile.f}'s Blog" xml.link SITE xml.description "#{@profile.f}'s Blog at #{SITE_NAME}" xml.language 'en-us' @blogs.each do |blog| xml.item do xml.title blog.title xml.description bl...
Ruby
xml.instruct! :xml, :version=>"1.0" xml.rss(:version=>"2.0") do xml.channel do xml.title "#{@profile.f}'s Blog" xml.link SITE xml.description "#{@profile.f}'s Blog at #{SITE_NAME}" xml.language 'en-us' @photos.each do |photo| xml.item do xml.title "Photo" xml.description "<a...
Ruby
module ApplicationHelper require 'digest/sha1' require 'net/http' require 'uri' def less_form_for name, *args, &block options = args.extract_options! form_for name, *(args << options.merge(:builder=>LessFormBuilder)), &block end def less_remote_form_for name, *args, &block options = ar...
Ruby
module FeedItemsHelper def x_feed_link feed_item link_to_remote image_tag('delete.png', :class => 'png', :width=>'12', :height=>'12'), :url => profile_feed_item_path(@profile, feed_item), :method => :delete end def commentable_text comment, in_html = true parent = comment.commentable case parent...
Ruby
module FriendsHelper def get_friend_link profile, target return wrap_get_friend_link(link_to('Sign-up to Follow', signup_path)) if profile.blank? return '' unless profile && target dom_id = profile.dom_id(target.dom_id + '_friendship_') return wrap_get_friend_link('') if profile == target return w...
Ruby
module ForumsHelper def forum_details(forum) "#{forum.posts.count} "+(forum.posts.count == 1 ? "post" : "posts")+" in #{forum.topics.count} "+(forum.topics.count == 1 ? "topic" : "topics") end def forum_last_post_info(forum) unless (forum.posts.empty?) post = forum.posts.last "#{time_ago...
Ruby
module ForumPostsHelper def forum_posts_li posts html = '' posts.each do |post| if post.topic and post.topic.forum html += "<li>In #{link_to sanitize(post.topic.title), forum_topic_path(post.topic.forum, post.topic), :href => forum_topic_path(post.topic.forum, post.topic)+'#'+dom_id(post) } ...
Ruby
module PhotosHelper include ActionView::Helpers::AssetTagHelper def image photo, size = :square, img_opts = {} return image_tag(image_path( photo, size), :class => size) if photo.image.blank? img_tag = image_tag(photo_path( photo, size), {:title=>photo.caption, :alt=>photo.caption, :class=>size}.merge(img...
Ruby
module HomeHelper def newest_pictures limit = 12 Photo.find(:all, :order => 'created_at desc', :limit => limit) end def recent_comments limit = 10 Comment.find(:all, :order => 'created_at desc', :limit => limit, :conditions => "commentable_type='Profile'") end def new_members(limit = 12) ...
Ruby
module Admin::UsersHelper end
Ruby
module MessagesHelper end
Ruby
# By Henrik Nyh <http://henrik.nyh.se> 2008-01-30. # Free to modify and redistribute with credit. require "rubygems" require "hpricot" module TextHelper # Like the Rails _truncate_ helper but doesn't break HTML tags or entities. def truncate_html(text, max_length = 30, ellipsis = "...") return if text.nil? ...
Ruby
module BlogsHelper def blogs_li blogs html = '' blogs.each do |b| html += "<li>#{link_to b.title, profile_blog_path(@profile, b)} written #{time_ago_in_words b.created_at} ago</li>" end html end def blog_body_content blog youtube_videos = blog.body.scan(/\[youtube:+.+\]/) ...
Ruby
module CommentsHelper end
Ruby
module ForumTopicsHelper def topic_last_post_info(topic) unless (topic.posts.empty?) post = topic.posts.last "#{time_ago_in_words post.created_at} ago by "+link_to(post.owner.f, profile_path(post.owner)) else "No posts" end end def topic_details(topic) "#{topic.posts.count}...
Ruby
require 'avatar/view/action_view_support' module ProfilesHelper include Avatar::View::ActionViewSupport def icon profile, size = :small, img_opts = {} return "" if profile.nil? img_opts = {:title => profile.full_name, :alt => profile.full_name, :class => size}.merge(img_opts) link_to(avatar_tag(prof...
Ruby
module AccountsHelper end
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: messages # # id :integer(4) not null, primary key # subject :string(255) # body :text # created_at :datetime # updated_at :datetime # sender_id :integer(4) # receiver_id :integer(4) ...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: forum_topics # # id :integer(4) not null, primary key # title :string(255) # forum_id :integer(4) # owner_id :integer(4) # created_at :datetime # updated_at :datetime # class ForumTopic < ActiveReco...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: blogs # # id :integer(4) not null, primary key # title :string(255) # body :text # profile_id :integer(4) # created_at :datetime # updated_at :datetime # class Blog < ActiveRecord::Base ha...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: photos # # id :integer(4) not null, primary key # caption :string(1000) # created_at :datetime # updated_at :datetime # profile_id :integer(4) # image :string(255) # class Photo < ActiveRecord::Base ...
Ruby
class ForumMailer < ActionMailer::Base def new_post(user,post) @subject = "New post on #{post.topic.title} from #{SITE_NAME}" @recipients = user.profile.email @body['user'] = user @body['post'] = post @from = MAILER_FROM_ADDRESS @sent_on = Time.new @conte...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: users # # id :integer(4) not null, primary key # login :string(255) # crypted_password :string(40) # salt :string(40) # created_at :datetime ...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: forum_posts # # id :integer(4) not null, primary key # body :text # owner_id :integer(4) # topic_id :integer(4) # created_at :datetime # updated_at :datetime # class ForumPost < ActiveRecord...
Ruby
class AccountMailer < ActionMailer::Base def signup(user) @subject = "Signup info from #{SITE_NAME}" @recipients = user.profile.email @body['user'] = user @from = MAILER_FROM_ADDRESS @sent_on = Time.new @headers = {} end def forgot_password(email...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: comments # # id :integer(4) not null, primary key # comment :text # created_at :datetime not null # updated_at :datetime not null # profile_id :integer(4) # commentable_type ...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: profiles # # id :integer(4) not null, primary key # user_id :integer(4) # first_name :string(255) # last_name :string(255) # website :string(255) # blog :string(255) ...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: feeds # # id :integer(4) not null, primary key # profile_id :integer(4) # feed_item_id :integer(4) # class Feed < ActiveRecord::Base belongs_to :feed_item belongs_to :profile attr_immutable :id, :profile_id, :feed_i...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: feed_items # # id :integer(4) not null, primary key # include_comments :boolean(1) not null # is_public :boolean(1) not null # item_id :integer(4) # item_type :string(255) # created_at ...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: friends # # id :integer(4) not null, primary key # inviter_id :integer(4) # invited_id :integer(4) # status :integer(4) default(0) # created_at :datetime # updated_at :datetime # class Friend < ActiveRec...
Ruby
# == Schema Information # Schema version: 2008100601002 # # Table name: forums # # id :integer(4) not null, primary key # name :string(255) # description :text # position :integer(4) # created_at :datetime # updated_at :datetime # class Forum < ActiveRecord::B...
Ruby
class HomeController < ApplicationController skip_before_filter :login_required def contact return unless request.post? body = [] params.each_pair { |k,v| body << "#{k}: #{v}" } HomeMailer.deliver_mail(:subject=>"from #{SITE_NAME} contact page", :body=>body.join("\n")) flash[:notice] = "Thank...
Ruby
class AccountsController < ApplicationController skip_before_filter :login_required, :except => :logout skip_after_filter :store_location layout 'plain' def login redirect_back_or_default(home_path) and return if @u @user = User.new return unless request.post? #plays double duty log...
Ruby
class PhotosController < ApplicationController skip_filter :login_required prepend_before_filter :get_profile before_filter :setup def index respond_to do |wants| wants.html {render} wants.rss {render :layout=>false} end end def show redirect_to profile_photos_path(@profi...
Ruby
class ForumsController < ApplicationController skip_filter :login_required, :only => [:show, :index] before_filter :setup def index @forums = Forum.find(:all, :order => "position ASC") get_response :xml_object => @forums end def show get_response end def new get_response end def ed...
Ruby
class ForumTopicsController < ApplicationController helper ForumsHelper skip_filter :login_required, :only => [:show, :index] before_filter :setup def index redirect_to forum_path(@forum) end def show @posts = @topic.posts.paginate(:all, :page => params[:page], :order => 'created_at DESC...
Ruby
class CommentsController < ApplicationController skip_filter :store_location, :only => [:create, :destroy] before_filter :setup def index @comments = Comment.between_profiles(@p, @profile).paginate(:page => @page, :per_page => @per_page) redirect_to @p and return if @p == @profile respond_to do ...
Ruby
class ForumPostsController < ApplicationController before_filter :setup skip_filter :login_required, :only => [:show, :index] def index redirect_to forum_path(@forum) end def show redirect_to forum_path(@forum) end def edit end def create @post = @topic.posts.build(params[:forum_po...
Ruby
class Admin::UsersController < ApplicationController before_filter :search_results, :except => [:destroy] def index render end def update @profile = Profile.find(params[:id]) respond_to do |wants| wants.js do render :update do |page| if @p == @profile ...
Ruby
class ProfilesController < ApplicationController include ApplicationHelper prepend_before_filter :get_profile, :except => [:new, :create, :index, :search] before_filter :setup, :except => [:index, :search] before_filter :search_results, :only => [:index, :search] skip_filter :login_required, :only=>[:show, ...
Ruby
class FriendsController < ApplicationController before_filter :setup skip_before_filter :login_required, :only=>:index skip_before_filter :store_location, :only => [:create, :destroy] def create respond_to do |wants| if Friend.make_friends(@p, @profile) friend = @p.reload.friend_of? @pro...
Ruby
class BlogsController < ApplicationController skip_filter :login_required, :only => [:index, :show] prepend_before_filter :get_profile before_filter :setup def index if @p && @p == @profile && @p.blogs.empty? flash[:notice] = 'You have not create any blog posts. Try creating one now.' red...
Ruby
class MessagesController < ApplicationController before_filter :can_send, :only => :create def index @message = Message.new @to_list = @p.friends if @p.received_messages.empty? && @p.has_network? flash[:notice] = 'You have no mail in your inbox. Try sending a message to someone.' ...
Ruby
class FeedItemsController < ApplicationController skip_filter :store_location before_filter :setup def destroy @profile.feeds.find(:first, :conditions => {:feed_item_id=>params[:id]}).destroy respond_to do |wants| wants.html do flash[:notice] = 'Item successfully removed from the rec...
Ruby
class ApplicationController < ActionController::Base helper :all include ExceptionNotifiable filter_parameter_logging "password" before_filter :allow_to, :check_user, :set_profile, :login_from_cookie, :login_required, :check_permissions, :pagination_defaults after_filter :store_location layout 'applic...
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.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
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/runner'
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/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/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/plugin'
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/dbconsole'
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/breakpointer'
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/console'
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/process/inspector'
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/reaper'
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/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