Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
public enum Order | |
{ | |
Ascending, | |
Descending | |
} |
require "fileutils" | |
root_dir = "/Users/jason/Downloads/images" | |
Dir.chdir(root_dir) | |
puts Dir.pwd | |
Dir.glob("**/*.{jpg}").each do |fname| | |
tfname = fname.split("/").last | |
if fname.match("[small|large|normal]_") | |
tfname = fname.split("_").last | |
end | |
p1,p2 = tfname[0,1],tfname[1,1] |
use your_databasse; | |
set @attribute_code = 'name'; | |
set @entity_type_id = '4'; | |
set @entity_id = '502'; | |
set @backend_type = | |
(select backend_type | |
from eav_attribute | |
where attribute_code = @attribute_code and |
// This is a manifest file that'll be compiled into application.js, which will include all the files | |
// listed below. | |
// | |
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | |
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. | |
// | |
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | |
// the compiled file. | |
// | |
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD |
require "bundler/capistrano" | |
set :application, "blog" | |
set :repository, "[email protected]:happypeter/blog.git" | |
set :scm, :git | |
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` | |
set :user, "deployer" | |
set :deploy_to, "/home/#{user}/#{application}" | |
set :deploy_via, :remote_cache | |
set :use_sudo, true |
the default index.html does not work well in prodution mode, so do not borther to config that, just delete it and go on.
To put things in production mode, do
rails g scaffold items name:string
rake db:migrate RAILS_ENV=production
rm public/index.html
#change route.rb point root to items#index
rake assets:precompile
sudo service nginx restart
./config/unicorn_init.sh stop
# sudo ln -s ~/nginx.conf unicorn.conf | |
upstream app_server { | |
server unix:/tmp/unicorn_padrino.sock fail_timeout=0; | |
} | |
server { | |
listen 80; | |
charset utf-8; | |
server_name db.innshine.com; |
#Session controller provides a token | |
#/controllers/api/sessions_controller.rb | |
class Api::SessionsController < Devise::SessionsController | |
before_filter :authenticate_user!, :except => [:create] | |
before_filter :ensure_params_exist, :except => [:destroy] | |
respond_to :json | |
def create | |
resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | |
return invalid_login_attempt unless resource |