2013-06-23 29 views
0

我刚刚启动了我的Rails应用程序与heroku(http://fast-reaches-9399.herokuapp.com/)。该搜索适用于本地开发环境,但不适用于生产环境。这可能是因为postgres与sqlite的问题?搜索工作在开发中,但没有在生产

我这样做:

group :development do 
    gem 'sqlite3', '1.3.5' 
end 

group :production do 
    gem 'pg', '0.12.2' 
end 

就像在本教程中(http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-heroku_setup)。

这是我的搜索相关代码。我用这个(http://railscasts.com/episodes/37-simple-search-form)寻求帮助。

/search.html.erb

<h2>Results:</h2> 

<ul> 
    <% @colleges.each do |college| %> 
     <li><%= link_to "#{college.name}", "#{college.url}" %></li> 
    <% end %> 
</ul> 

application.html.erb(我的布局文件)

<%= form_tag("/search", :method => 'get') do -%> 
    <li id="search"> <%= search_field_tag :search, params[:search] %></li> 
<% end -%> 

static_pages_controller.rb

def search 
    @colleges = College.search(params[:search]) 
end 

college.rb

def self.search(search) 
    if search 
    find(:all, :conditions => ['name LIKE ?', "%#{search}%"]) 
    else 
    find(:all) 
    end 
end 
+0

'LIKE' Postgres里是大小写敏感的,会是你的问题?尝试'名称ILIKE?'是不区分大小写的。 – declan

回答

1

正如declan所说,这是由于postgres在使用LIKE时区分大小写的事实造成的。使用ILIKE的问题是它不再在sqlite中工作。

的一种黑客其中工程是改变搜索条件:

find(:all, :conditions => ['UPPER(name) LIKE ?', "%#{search.upcase}%"]) 
+0

工作完美!谢谢。 –

+0

不客气!你能将答案标记为已接受吗? :) –

相关问题