Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| module ActiveRecord::UnionScope | |
| def self.included(base) | |
| base.send :extend, ClassMethods | |
| end | |
| module ClassMethods | |
| def union_scope(*scopes) | |
| id_column = "#{table_name}.#{primary_key}" | |
| sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ") | |
| where "#{id_column} IN (#{sub_query})" |
| require 'socket' | |
| require 'openssl' | |
| require 'puma/server' | |
| require 'ds9' | |
| class Server < DS9::Server | |
| def initialize socket, app | |
| @app = app | |
| @read_streams = {} | |
| @write_streams = {} |
| require 'webrick' | |
| require 'webrick/https' | |
| require 'ds9' | |
| class HTTP2Server < WEBrick::HTTPServer | |
| SETTINGS = [ [DS9::Settings::MAX_CONCURRENT_STREAMS, 100] ] | |
| class HTTP2Response < WEBrick::HTTPResponse | |
| def initialize config, ctx, stream_id | |
| @ctx = ctx |
📆 Jun 23-24, 2016
🌏 Web site: http://reddotrubyconf.com/ Twitter: http://twitter.com/reddotrubyconf
💁 Ping me @cheeaun on Twitter or leave a comment below if you found some awesome stuff for #rdrc2016. This gist will be updated whenever there's new stuff.
🕙 Previously, on RedDotRubyConf...
Ruby has heroes. Demigods who show us how to write better code. Turns out: they're just ordinary developers! This is the story of how I discovered that by becoming Ruby-famous. In the process, I learned our hero culture is toxic.
Want to keep Ruby weird? Stop listening to us (right after my talk).
| # A little toy file demonstrating how to build chainable | |
| # data transformations that reveal some amount of intent | |
| # through named extracted methods. | |
| # | |
| # Kudos to @mfeathers for giving me the idea to try this | |
| # | |
| # Copyright Test Double, LLC, 2016. All Rights Reserved. | |
| require_relative "marketing_refinements" |