Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
class Attachment < ActiveRecord::Base | |
mount_uploader :attachment, AttachmentUploader | |
# Associations | |
belongs_to :attached_item, polymorphic: true | |
# Validations | |
validates_presence_of :attachment |
awk '/^Started /{t=$8} /^Completed /{print t,$5,$7,$10}' log/production.log | sort -k 2,2nr | head -20 |
require 'benchmark/ips' | |
h = { foo: :bar } | |
Benchmark.ips do |r| | |
r.report('#[]') { h[:foo] } | |
r.report('#fetch') { h.fetch(:foo) } | |
end |
/* 后端数据 */ | |
var data = { | |
"10;20;30": { | |
price: 5, | |
count: 1 | |
}, | |
"10;20;31": { | |
price: 10, | |
count: 2 | |
}, |
Dear Rubyists,
I just lost a contract because of my code in a Rails project.
The specific code in question is related to a "posting a comment" feature. Here are the details:
In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.
The "senior developer", whom is the stake holder's right hand man, said this:
module Order | |
module Ranking | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
def update_r_ranking | |
t = self | |
t.r_ranking = Topic.calculate_ranking(t.pushes_count, t.created_at) | |
t.save(:validate => false) |