note

笔记

rails

控制器处理完ajax请求后,两种返回方式时:

  • render :text => ‘aa’,此时前端的回调函数的

    1
    2
    3
    function(data){
    alert(data);//此时打印:'aa'
    }

  • redirect_to :back,此时前端的回调函数的

    1
    2
    3
    function(data){
    alert(data);//返回xml代码吧
    }

Nginx

作为文件下载器

1
2
3
4
5
6
7
location / {
#root html;
#index index.html index.htm;
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_header Content-Disposition: 'attachment;';
}
}
  • 在nginx 目录下放置待下载文件
  • 打开浏览器输localhost/panda.mp4

参考链接

http://blog.chinaunix.net/uid-26000296-id-5757745.html

Unicorn见习

参考链接(http://blog.yoosan.me/2015/08/09/Linux(Ubuntu)%E4%B8%8A%E9%83%A8%E7%BD%B2rails%E5%BA%94%E7%94%A8,%E4%BD%BF%E7%94%A8unicorn%E5%92%8Cnginx/)
  • 新建/appname/config/unicorn.rb,配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# set path to application
# app_dir is your rails app directory path
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir
# Set unicorn options
worker_processes 2
preload_app true
timeout 30
# Set up socket location
listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64
# Logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
# Set master PID location
pid "#{shared_dir}/pids/unicorn.pid"
1
2
3
* 创建目录mkdir -p shared/pids shared/sockets shared/log(在更目录中)
* 运行命令bundle exec unicorn -c config/unicorn.rb -p 3000 -D