Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| # coding: utf-8 | |
| require 'rack/urlmap' | |
| require File.join(File.dirname(__FILE__), 'app') | |
| require File.join(File.dirname(__FILE__), 'api', 'v1') | |
| routes = Rack::URLMap.new( | |
| '/' => Sinatra::Application, | |
| '/api/v1/' => ApiV1 | |
| ) |
| namespace :tasks do | |
| namespace :create do | |
| desc "Create all survey templates" | |
| task :all => [:task1, :task2, :task3] | |
| desc "desc1" | |
| task :task1 => :environment do | |
| end |
| # default.custom.yaml | |
| # save it to: | |
| # ~/.config/ibus/rime (linux) | |
| # ~/Library/Rime (macos) | |
| # %APPDATA%\Rime (windows) | |
| patch: | |
| schema_list: | |
| - schema: luna_pinyin # 朙月拼音 | |
| - schema: terra_pinyin # 地球拼音 dì qiú pīn yīn |
| Follow the instructions here: The Hitchhiker's Guide to Riding a | |
| Mountain Lion http://j.mp/Qm5UJD, including installing XQuartz. | |
| After installing XQuartz set the correct path to the X11 library to | |
| install Ruby 1.8.7-p358 with rbenv: | |
| export CPPFLAGS=-I/opt/X11/include | |
| then let the compiler know where gcc-4.2 is: |
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:
| ### | |
| #Step 1 - Generate server certificates etc... (most of this code is horribly ripped off from nodejs docs currently -> http://nodejs.org/docs/latest/api/tls.html) | |
| ### | |
| #Assuming your starting from a clean directory | |
| mkdir server | |
| cd server | |
| #generate private key |
| #!/usr/bin/ruby | |
| # Runs as follows: | |
| # | |
| # ~$ ruby tls-cert-generator.rb | |
| require "openssl" | |
| require "socket" |
| ## | |
| # Use this behind the scenes to migrate files from your filesystem to Amazon S3 | |
| # %: rake paperclip_migration:migrate_to_s3 | |
| ## | |
| namespace :attachments do | |
| desc "migrate files from filesystem to s3" | |
| task :migrate_to_s3 => :environment do | |
| require 'aws/s3' |
| #!/bin/sh | |
| # Just copy and paste the lines below (all at once, it won't work line by line!) | |
| # MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY! | |
| function abort { | |
| echo "$1" | |
| exit 1 | |
| } | |
| set -e |