【发布时间】:2013-06-20 06:32:31
【问题描述】:
我刚刚使用 heroku (http://fast-reaches-9399.herokuapp.com/) 启动了我的 rails 应用程序。搜索适用于我的本地开发环境,但不适用于生产环境。这可能是因为 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
学院.rb
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
【问题讨论】:
-
LIKEin postgres 区分大小写,这可能是您的问题吗?尝试name ILIKE ?不区分大小写。
标签: ruby-on-rails search dev-to-production