Am Dienstag,30. Juli 2013 12:23:46 UTC + 2 schrieb Steven Stadler:
嘿伙计们!我确实为标准refniery应用程序的扩展创建了一个搜索表单。此扩展名代表可以通过三个搜索词找到的出版物,如“作者”,“日期”和“标题”。 它适用于我的本地机器。我将它部署到heroku后,我收到此错误消息......“我们很抱歉,但出了点问题。” 我希望有人可以帮助我...我使用Rails 3.2.13和Ruby 1.9.2和2.0.0以下是完整日志的一部分:
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:155:in `invalidate'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/middleware/static.rb:63:in `call'
2013-07-30T10:14:32.782114+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.13/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2013-07-30T10:14:32.782624+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
2013-07-30T10:14:32.782624+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-3.2.13/lib/rails/rack/log_tailer.rb:17:in `call'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-3.2.13/lib/rails/engine.rb:479:in `call'
2013-07-30T10:14:32.782624+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:in `call!'
2013-07-30T10:14:32.782624+00:00 app[web.1]:
2013-07-30T10:14:32.782624+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2013-07-30T10:14:32.782624+00:00 app[web.1]:
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
2013-07-30T10:14:32.782624+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2013-07-30T10:14:32.782472+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-3.2.13/lib/rails/application.rb:223:in `call'
2013-07-30T10:14:32.784993+00:00 app[web.1]: Rendered vendor/extensions/publications/app/views/refinery/publications/publications/index.html.erb within layouts/application (721.8ms)
2013-07-30T10:14:32.784993+00:00 app[web.1]: Completed 500 Internal Server Error in 738ms
2013-07-30T10:14:32.784993+00:00 app[web.1]: Processing by Refinery::Publications::PublicationsController#search as HTML
2013-07-30T10:14:32.784993+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"88vYJKWcs7Xjb/OGHVYg13AW5SibRJGk8OvQrbeliqA=", "search_author"=>"ang", "search_title"=>"", "search_year"=>"", "commit"=>"Search", "locale"=>:en}
我的路线(来自扩展名):
Refinery::Core::Engine.routes.append do
# Frontend routes
namespace :publications do
resources :publications, :path => '', :only => [:index, :show]
match '/get_pubs' => 'publications#search'
end
# Admin routes
namespace :publications, :path => '' do
namespace :admin, :path => 'refinery' do
resources :publications, :except => :show do
collection do
post :update_positions
end
end
end
end
end
我的搜索表单:
<% content_for :body do %>
<ul id="publications">
<%= form_tag "/publications/get_pubs", method: :post do %>
<table>
<tr>
<td>
<b>Author:</b>
</td>
<td>
<b>Title:</b>
</td>
<td>
<b>Year:</b>
</td>
</tr>
<tr>
<td>
<%= text_field_tag :search_author, '' %>
</td>
<td>
<%= text_field_tag :search_title, '' %>
</td>
<td>
<%= text_field_tag :search_year, '' %>
</td>
</tr>
</table>
<%= submit_tag "Search" %>
<% end %>
.....
我的模特:
module Refinery
module Publications
class Publication < Refinery::Core::BaseModel
self.table_name = 'refinery_publications'
attr_accessible :title, :authors, :year, :publisher, :position
acts_as_indexed :fields => [:title, :authors, :publisher]
validates :title, :presence => true, :uniqueness => true
def self.search(query1,query2,query3)
# where(:title, query) -> This would return an exact match of the query
where("authors like ?", "%#{query1}%").where("title like ?", "%#{query2}%" ).where("year like ?", "%#{query3}%" )
end
end
end
end
我的控制器:
module Refinery
module Publications
class PublicationsController < ::ApplicationController
before_filter :find_all_publications
before_filter :find_page
def index
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @publication in the line below:
present(@page)
end
def show
@publication = Publication.find(params[:id])
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @publication in the line below:
present(@page)
end
def search
@publications = Publication.search(params[:search_author],params[:search_title],params[:search_year]).order("year").reverse_order
#@publications = @publications.first
render action: 'index'
end
protected
def find_all_publications
@publications = Publication.order("year").reverse_order
end
def find_page
@page = ::Refinery::Page.where(:link_url => "/publications").first
end
end
end
end
答案 0 :(得分:1)
这里发生了一些事情。首先,您可能正在开发针对SQLite,其行为与PostgreSQL不同。如果你要部署到Heroku,我建议设置一个本地Postgres安装来开发,因为它可以让你更快地发现这些问题,并为你节省很多麻烦。这个tutorial是一个有用的起点。
至于你遇到的具体问题,Postgres LIKE只是字符串比较,但是日志显示你试图在年份列上做一个LIKE,这是一个整数。我无法测试这一点,但是用这样的方法替换模型中的搜索子句可以解决问题:
where("authors like ?", "%#{query1}%").where("title like ?", "%#{query2}%" ).where("year::text like ?", "%#{query3}%")