2013-07-30 3 views
0

Am Dienstag, 30. Juli 2013 12:23:46 UTC + 2 schrieb Стивен Stadler:Форма поиска работает на локальной машине, а не на Heroku

Эй, ребята! Я создал форму поиска для расширения стандартного приложения для замены. Это расширение означает публикации, которые можно найти с тремя поисковыми терминами, такими как «автор», «дата» и «название». Он работает на моей локальной машине. После того, как я развожу его на геройку, я просто получаю сообщение об ошибке ... «Мы сожалеем, но что-то пошло не так». Я надеюсь, что кто-то может мне помочь ... Я использую Rails 3.2.13 и Руби 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 %> 

    ..... 

My Model:

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 
+2

Добавить полный журнал, потому что никто здесь может угадать, что было брошено исключение только от смотрения на backtrace. –

ответ

1

Есть несколько вещей, которые происходят здесь. Во-первых, вы, скорее всего, развиваетесь против SQLite, который ведет себя иначе, чем PostgreSQL. Я бы рекомендовал настроить локальную установку Postgres для разработки против, если вы собираетесь развертывать в Heroku, так как это позволит вам быстрее поймать эти проблемы и сэкономить много головных болей. Это tutorial - это полезное место для начала.

Что касается конкретной проблемы, с которой вы столкнулись, Postgres LIKE - это сравнение строк, но, как показывают журналы, вы пытаетесь сделать LIKE в столбце year, который является целым числом. Я не могу проверить это, чтобы быть уверенным, но заменив пункт поиска в модели с чем-то, как это должно решить проблему:

where("authors like ?", "%#{query1}%").where("title like ?", "%#{query2}%").where("year::text like ?", "%#{query3}%") 
Смежные вопросы