Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
# ruby-2.5.0 | |
user system total real | |
YAML 15.112795 0.030577 15.143372 ( 15.190573) | |
JSON 0.648957 0.001520 0.650477 ( 0.652856) | |
Marshal 0.474775 0.000922 0.475697 ( 0.477678) | |
MessagePack 0.326430 0.001763 0.328193 ( 0.330159) | |
# ruby-2.4.3 | |
user system total real | |
YAML 20.400000 0.050000 20.450000 ( 20.517600) |
require 'rubygems' | |
require 'usb' # this is the ruby-usb gem, I'm also using libusb 1.0 and linux | |
require 'logger' | |
class MagTek | |
def initialize | |
@device = find_device | |
interface = @device.interfaces.first | |
@endpoint = interface.endpoints.first | |
@logger = Logger.new("/var/log/monitor_usb.log") |
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:
From: Chris DeSalvo <[email protected]> | |
Subject: Why we can't process Emoji anymore | |
Date: Thu, 12 Jan 2012 18:49:20 -0800 | |
Message-Id: <[email protected]> | |
--Apple-Mail=_6DEAA046-886A-4A03-8508-6FD077D18F8B | |
Content-Transfer-Encoding: quoted-printable | |
Content-Type: text/plain; | |
charset=utf-8 |
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
# Ways to execute a shell script in Ruby | |
# Example Script - Joseph Pecoraro | |
cmd = "echo 'hi'" # Sample string that can be used | |
# 1. Kernel#` - commonly called backticks - `cmd` | |
# This is like many other languages, including bash, PHP, and Perl | |
# Synchronous (blocking) | |
# Returns the output of the shell command | |
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |