开发者

Search Form Not Working In Production

开发者 https://www.devze.com 2023-04-10 22:18 出处:网络
For some reason my search form is not working correctly when my app is launched, in the localhost its working without a problem but when I go to use the search on the launched app the search seems to

For some reason my search form is not working correctly when my app is launched, in the localhost its working without a problem but when I go to use the search on the launched app the search seems to be broken. I can't figure out why, I followed the Railscasts Simple Search Form 开发者_开发技巧to implement it and it hasn't been a problem in local at all.

My user model looks like

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

My users controller index looks like

   def index
     @users = User.search(params[:search])
     @title = "All Users"

     respond_to do |format|
       format.html
       format.json { render :json => @users }
     end
   end

My user index view

 <% form_tag users_path, :method => 'get' do %>
   <p>
     <%= text_field_tag :search, params[:search] %>
     <%= submit_tag "Search", :name => nil %>
   </p>
 <% end %>

 <ul class="users">
   <%= render @users %>
 </ul>

Not only is the search not working correctly but when I type a name and its not there it should return all users but instead it returns an empty page, not sure if thats relevant but I thought I'd be as through as possible. Thanks.


i am assuming that you are using MySQL for development and heroku's PostgreSQL for production. Normally errors like this are probably due to differences in production and development database environments.

The problem could be the statement

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

change it to this

find(:all, :conditions => ['name ILIKE ?', "%#{search}%"])

notice the ILIKE.

Always best to use same database in development and production, as this will prevent problems later on. Also checkout the heroku docs here. if you are using heroku. Hope it helps


Are you using a hosting provider or are you running the app in 'production' on a local server? If you are using Heroku, Heroku uses Postgres which can handle sql queries differenly. To test you could setup Postgres in your dev environment and check the results of your queries.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号