我终于可以使用capistrano
进行部署了,可是却出现了难以预见的错误,Google 了很久也没有解决。
系统环境:
Linode 512, RVM Mulit-User, Ruby 1.9.3, Rails 3.2.8, PostgreSQL 9.1其他基本都是最新,系统是Ubuntu12.06 64bit LTS
问题如下:
看似好像解决了,现在重点是问题二
问题一
部署成功之后,老是提示无法加载 /asset/
目录下的内容,但是已经预编译了啊,而且 /asset/
目录下也有相关的文件,纠结中。
最后开启了 rails 的production.rb
中的config.serve_static_assets = true
解决了问题,但是怀恨在心啊!
我的 nginx 文件配置:
# /etc/nginx/sites-enabled/slyu
upstream slyu_backend {
server unix:/tmp/unicorn.slyu.sock fail_timeout=0;
}
server {
listen 80;
server_name slyu.chunlea.org;
root /home/slyu/apps/slyu/current/public;
location ~ ^/(assets)/ {
root /home/slyu/apps/slyu/current/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_pass http://slyu_backend;
}
}
我的Unicorn.rb
和deploy.rb
是参照 Ruby-China 的修改的。应该不会有问题,就是替换了路径。
希望各位指点一二。
问题二:
系统可以访问,但是老是出现 500 错误。错误提示:
Started GET "/admin/users?page=2" for 112.234.126.91 at 2012-08-30 01:23:14 +0000
Processing by Admin::UsersController#index as HTML
Parameters: {"page"=>"2"}
Rendered admin/users/index.html.erb within layouts/application (42.2ms)
Completed 500 Internal Server Error in 242ms
ActionView::Template::Error (PG::Error: ERROR: prepared statement "a1" already exists
: SELECT COUNT(*)
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind in ('v','r')
AND c.relname = $1
AND n.nspname = ANY (current_schemas(false))
):
9: </tr>
10: </thead>
11: <tbody>
12: <% @users.each do |user| %>
13: <tr id="#user_<%= user.id %>">
14: <td><%= link_to user.userid, admin_user_path(user) %></td>
15: <td><%= user.name %></td>
app/views/admin/users/index.html.erb:12:in `_app_views_admin_users_index_html_erb__1504903244061183802_16634340'
app/controllers/admin/users_controller.rb:6:in `index'
我的users_controller.rb
:
def index
@page_title=t('page_title.admin.users')
@users = User.paginate(:page => params[:page], :per_page => 10)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
相关的 view:
<%- model_class = User -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human %></h1>
</div>
<table class="table table-striped">
<thead>
<tr>
<th><%= model_class.human_attribute_name(:userid) %></th>
<th><%= model_class.human_attribute_name(:name) %></th>
<th><%= model_class.human_attribute_name(:email) %></th>
<th><%= model_class.human_attribute_name(:created_at) %></th>
<th><%=t '.actions', :default => t("helpers.actions") %></th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr id="#user_<%= user.id %>">
<td><%= link_to user.userid, admin_user_path(user) %></td>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= user.created_at %></td>
<td>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_admin_user_path(user), :class => 'btn btn-mini' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
admin_user_path(user),
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-mini btn-danger'
%>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="apple_pagination">
<div clas="page_info">
<%= page_entries_info @posts %>
</div>
<%= will_paginate @users %>
</div>
<%= link_to t('.new', :default => t("helpers.links.new")),
user_registration_path,
:method => :post,
:class => 'btn btn-primary' %>
到底是什么问题呢??