0

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
4

1 回答 1

1

这里发生了一些事情。首先是您可能正在针对行为与 PostgreSQL 不同的 SQLite 进行开发。如果您要部署到 Heroku,我建议您设置一个本地 Postgres 安装以进行开发,因为它可以让您更快地发现这些问题并为您省去很多麻烦。本教程是一个有用的起点。

至于您遇到的具体问题,Postgres LIKE 仅是字符串比较,但正如日志显示的那样,您正试图在整数年列上执行 LIKE。我无法确定这一点,但是用类似这样的东西替换模型中的搜索子句应该可以解决问题:

where("authors like ?", "%#{query1}%").where("title like ?", "%#{query2}%" ).where("year::text like ?", "%#{query3}%")
于 2013-07-30T16:18:11.900 回答