我刚刚启动了我的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
'LIKE' Postgres里是大小写敏感的,会是你的问题?尝试'名称ILIKE?'是不区分大小写的。 – declan