Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
# Path to your oh-my-zsh installation. | |
export ZSH=$HOME/.oh-my-zsh | |
# Set name of the theme to load. | |
# Look in ~/.oh-my-zsh/themes/ | |
# Optionally, if you set this to "random", it'll load a random theme each | |
# time that oh-my-zsh is loaded. | |
ZSH_THEME="robbyrussell" | |
# Uncomment the following line to use case-sensitive completion. |
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder | |
delegate :capture, :content_tag, :tag, to: :@template | |
%w[text_field text_area password_field collection_select email_field].each do |method_name| | |
define_method(method_name) do |name, *args| | |
errors = object.errors[name].any?? " error" : "" | |
error_msg = object.errors[name].any?? content_tag(:span, object.errors[name].join(","), class: "help-inline") : "" | |
content_tag :div, class: "control-group#{errors}" do |
* Go to https://code.google.com/apis/console, log in with your Google account and click on API Access. | |
* Create OAuth2 credentials by clicking the big blue OAuth2 button. | |
* Set the callback url and the name of your app (can be edited later) | |
* The Google Key (as it is referred to by OmniAuth) is the Client ID | |
* The Google Secret (as it is referred to by OmniAuth) is the Client Secret | |
* Use those credentials as per your documentation for implementing OAuth2 authentication. | |
The Google OmniAuth strategy for OAuth2 is here: https://github.com/zquestz/omniauth-google-oauth2. Look in the examples folder for details on the rest of the implementation. |
<% flash.each do |name, msg| %> | |
<div class="alert alert-<%= name == :notice ? "success" : "error" %>"> | |
<a class="close" data-dismiss="alert">×</a> | |
<%= msg %> | |
</div> | |
<% end %> |
导出数据库pg_dump -Fc mydb > db_name.dump | |
导入数据库 pg_restore -d mydb db_name.dump | |
导出 pg_dump mydb > db_name.sql | |
表导出 pg_dump database -t table > table.sql | |
加上' -a '可只到导出表内容,不导出表结构 |
file = File.join(Rails.root, 'log/markdown.log') | |
File.new(file, 'w+') unless File.exist?(file) | |
logger = Logger.new(file) | |
logger.info("#{Time.now}: Share##{_id}'s price is from #{latest_price} to #{new_price}") | |
logger.close |
<VirtualHost *:80> | |
ServerName anderweb.ca | |
RewriteEngine on | |
RewriteRule ^(.*)$ http://www.anderweb.ca$1 [R=301,L] | |
</VirtualHost> |
1 服务器上: | |
2 git init --bare --shared reggin.git | |
3 本地: | |
4 git remote add origin xxx@git.xxx.xx:/home/dev/repos/xxxx.git |
begin #开始 | |
raise.. #抛出异常 | |
rescue [ExceptionType = StandardException] #捕获指定类型的异常 缺省值是StandardException | |
$! #表示异常信息 | |
$@ #表示异常出现的代码位置 | |
else #其余异常 | |
.. | |
ensure #不管有没有异常,进入该代码块 |