Skip to content

Instantly share code, notes, and snippets.

@tyabe
Created September 1, 2013 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyabe/6403230 to your computer and use it in GitHub Desktop.
Save tyabe/6403230 to your computer and use it in GitHub Desktop.
Padrino 0.11 以降で Better Errors を使う ref: http://qiita.com/tyabe/items/b5300572a9dfd7f7e039
module Sample
class App < Padrino::Application
#...
set :protect_from_csrf, except: %r{/__better_errors/\d+/\w+\z}
if Padrino.env == :development
# Setup better_errors
Padrino::Application.use BetterErrors::Middleware
BetterErrors.application_root = PADRINO_ROOT
BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
Padrino::Application.set :exclude_from_protection, '/__better_errors' # Append this
# ...
end
if Padrino.env == :development
module Rack
module Protection
class AuthenticityToken
def accepts_with_allowed_path?(env)
if defined?(Padrino::Application.exclude_from_protection)
[Padrino::Application.exclude_from_protection].flatten.each do |path|
return true if Regexp.new(path).match(env['REQUEST_PATH'])
end
end
accepts_without_allowed_path?(env)
end
alias_method_chain :accepts?, :allowed_path
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment