forked from caok/books-share
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bay6/master
merge back sphinx
- Loading branch information
Showing
14 changed files
with
195 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load 'deploy' | ||
# Uncomment if you are using Rails' asset pipeline | ||
load 'deploy/assets' | ||
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
|
||
# cancan exception handler | ||
# cancan exception handler | ||
rescue_from CanCan::AccessDenied do |exception| | ||
redirect_to root_url, alert: I18n.t("unauthorized.default") | ||
end | ||
|
||
protected | ||
def sphinx_escape(s, default='') | ||
s = default.strip if s.nil? | ||
keywords = s.split(/\s+/).map{|k| Riddle.escape("#{k}")} | ||
keywords.join(' | ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ThinkingSphinx::Index.define :book, :with => :active_record do | ||
indexes name, sortable: true | ||
indexes content | ||
indexes publishing_house | ||
indexes :ISBN | ||
|
||
indexes authors.name, :as => :authors | ||
|
||
has id, created_at, updated_at | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/*= form_tag '/search', class: 'navbar-search' do*/ | ||
/*= text_field_tag 'q', @q, class: 'input-medium search-query', placeholder: @q || 'Search'*/ | ||
form.navbar-search action="/search" method="get" target='_blank' | ||
form.navbar-search action="/books" method="get" | ||
input.search-query.span3 name="q" placeholder=t("layout.search") type="text" value=(params[:q]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#uyan_frame | ||
javascript: | ||
var uyan_config = { | ||
du: "#{Rails.env.production? ? "book-share.cloudfoundry.com" : "test.me"}", | ||
su: "#{su}" | ||
}; | ||
script type="text/javascript" id="UYScript" src="http://v1.uyan.cc/js/iframe.js?UYUserId=1777087" async="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#encoding:utf-8 | ||
require 'bundler/capistrano' | ||
require 'thinking_sphinx/capistrano' | ||
|
||
set :application, "books-share" | ||
#set :repository, "git://github.com/caok/books-share.git" | ||
set :repository, File.expand_path('../../.git/', __FILE__) | ||
#set :branch, "master" | ||
|
||
set :scm, :git | ||
|
||
set :user, ENV['USER'] || "ruby" | ||
set :use_sudo, false | ||
|
||
# 部署路径修改为当前用户的目录,如果用默认的根目录且没有root权限会引起Permission denied的错误 | ||
set :deploy_to, "/home/#{user}/apps/#{application}" | ||
set :deploy_via, :remote_cache # 不要每次都获取全新的repository | ||
set :deploy_server, 'localhost' | ||
|
||
set :bundle_without, [:development, :test] | ||
|
||
# for rbenv | ||
set :rbenv_version, ENV['RBENV_VERSION'] || "1.9.3-p392" | ||
set :default_environment, { | ||
'PATH' => "/home/#{user}/.rbenv/shims:/home/#{user}/.rbenv/bin:$PATH", | ||
'RBENV_VERSION' => "#{rbenv_version}", | ||
} | ||
|
||
role :web, "#{deploy_server}" # Your HTTP server, Apache/etc | ||
role :app, "#{deploy_server}" # This may be the same as your `Web` server | ||
role :db, "#{deploy_server}", :primary => true # This is where Rails migrations will run | ||
#role :db, "your slave db-server here" | ||
|
||
after "deploy", "deploy:cleanup" # keep only the last 5 releases | ||
|
||
namespace :deploy do | ||
desc "Start Application" | ||
task :start, :roles => :app do | ||
run "cd #{current_path}; RAILS_ENV=production bundle exec unicorn_rails -c config/unicorn.rb -D" | ||
end | ||
|
||
desc "Stop Application" | ||
task :stop, :roles => :app do | ||
run "kill -QUIT `cat #{shared_path}/pids/unicorn.#{application}.pid`" | ||
end | ||
|
||
desc "Restart Application" | ||
task :restart, :roles => :app do | ||
run "kill -USR2 `cat #{shared_path}/pids/unicorn.#{application}.pid`" | ||
end | ||
|
||
desc "Populates the Production Database" | ||
task :seed do | ||
run "cd #{current_path}; bundle exec rake db:seed" | ||
end | ||
|
||
task :setup_config, roles: :app do | ||
run "mkdir -p #{shared_path}/config" | ||
put File.read("config/database.yml.example"), "#{shared_path}/config/database.yml" | ||
end | ||
after "deploy:setup", "deploy:setup_config" | ||
|
||
task :symlink_config, roles: :app do | ||
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" | ||
end | ||
after "deploy:finalize_update","deploy:symlink_config" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
development: &default | ||
enable_star: 1 | ||
min_infix_len: 1 | ||
ngram_len: 1 | ||
ngram_chars : "U+3000..U+2FA1F" | ||
|
||
production : | ||
<<: *default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,57 @@ | ||
# config/unicorn.rb | ||
worker_processes 3 | ||
timeout 30 | ||
preload_app true | ||
# encoding: utf-8 | ||
# Spawn unicorn master worker for user apps (group: apps) | ||
user ENV['USER'] || 'ruby', ENV['USER'] || 'ruby' | ||
|
||
# Set your full path to application. | ||
user = ENV['USER'] || 'ruby' | ||
application = "books-share" | ||
app_path = "/home/#{user}/apps/#{application}" | ||
shared_path = "#{app_path}/shared" | ||
current_path = "#{app_path}/current" | ||
|
||
# Set unicorn options | ||
worker_processes 2 | ||
preload_app true # Preload our app for more speed | ||
timeout 180 | ||
# 可同时监听 Unix 本地 socket 或 TCP 端口 | ||
listen 9000, :tcp_nopush => true | ||
#listen "/tmp/unicorn.#{application}.sock", :backlog => 64 | ||
|
||
# Fill path to your app | ||
working_directory current_path | ||
|
||
# Should be 'production' by default, otherwise use other env | ||
rails_env = 'production' | ||
|
||
# Log everything to one file | ||
stderr_path "log/unicorn.log" | ||
stdout_path "log/unicorn.log" | ||
# Set master PID location | ||
pid "#{shared_path}/pids/unicorn.#{application}.pid" | ||
|
||
if GC.respond_to?(:copy_on_write_friendly=) | ||
GC.copy_on_write_friendly = true | ||
end | ||
|
||
before_fork do |server, worker| | ||
ActiveRecord::Base.connection.disconnect! | ||
|
||
old_pid = "#{server.config[:pid]}.oldbin" | ||
if File.exists?(old_pid) && server.pid != old_pid | ||
begin | ||
Process.kill("QUIT", File.read(old_pid).to_i) | ||
rescue Errno::ENOENT, Errno::ESRCH | ||
# someone else did our job for us | ||
end | ||
end | ||
end | ||
|
||
after_fork do |server, worker| | ||
ActiveRecord::Base.establish_connection | ||
end | ||
|
||
# 修正无缝重启unicorn后更新的Gem未生效的问题,原因是config/boot.rb会优先从ENV中获取BUNDLE_GEMFILE, | ||
# 而无缝重启时ENV['BUNDLE_GEMFILE']的值并>未被清除,仍指向旧目录的Gemfile | ||
before_exec do |server| | ||
ENV["BUNDLE_GEMFILE"] = "#{current_path}/Gemfile" | ||
end |