This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% cache(:action=>"me_action",:action_prefix=>"some_prefix") do %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% cache("name") do %> | |
do some view stuff here | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WidgetsController < ApplicationController | |
#bad formatting here b/c of wordpress (remove space before 'only' if you copy this next line of code) | |
cache_sweeper :widget_sweeper, : only => [:create,:update,:destroy] | |
caches_action :show, :if => Proc.new { |x| x.cacheable? } | |
def show | |
#... | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WidgetSweeper < ActionController::Caching::Sweeper | |
observe Widget | |
def after_update(widget) | |
expire_cache_for(widget) | |
end | |
def after_destroy(widget) | |
expire_cache_for(widget) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :init | |
def cacheable? | |
@user.blank? ? true : false | |
end | |
def init | |
@user = nil | |
@user = User.find(session[:user_id]) if session[:user_id] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WidgetsController < ApplicationController | |
caches_action :show | |
def show | |
#... | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bcrypt' | |
module Lock | |
class CreatePasswordFileGenerator < Rails::Generators::Base | |
argument :password, :type => :string | |
source_root File.expand_path('../templates', __FILE__) | |
def create_password_file | |
password_salt = BCrypt::Engine.generate_salt | |
password_hash = BCrypt::Engine.hash_secret(password, password_salt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "lock" | |
require "rails" | |
module Lock | |
class Engine < Rails::Engine | |
initializer "lock.extend_application_controller" do | |
ActiveSupport.on_load(:action_controller) do | |
include LockApplicationController::InstanceMethods | |
extend LockApplicationController::ClassMethods | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LockApplicationController | |
module ClassMethods | |
def lock(opts={}) | |
before_filter { |c| c.lock_filter opts[:actions] } | |
end | |
end | |
module InstanceMethods | |
def lock_filter(actions=nil) | |
if locked_action?(actions) and session[:lock_opened]!=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOCK_PATH = File.dirname(__FILE__) + "/lock" | |
require "#{LOCK_PATH}/engine.rb" | |
require "bcrypt" | |
module Lock | |
def self.passwords_match?(password) | |
begin | |
hashed_combo = IO.read("#{Rails.root}/config/lock_password") | |
rescue | |
return false |