0

I've just deployed my first app on Heroku with Postgres and I'm getting an error when querying data to the models. It's been working properly with local MySQL database when the app queries this through the controller:

SELECT "locations".* 
FROM "locations" 
WHERE (id LIKE '%1%' OR user_id LIKE '%1%')):

 18:   </thead>
 19: 
 20:   <tbody>
 21:     <% @locations.each do |location| %>
 22:       <tr>
 23:         <td><%= location.id %></td>
 24:         <td><%= location.user.name %></td>
 FATAL -- : [e8968d66-5740-4005-9236-fd3e4cc61542] app/views/locations/index.html.erb:21:in `_app_views_locations_index_html_erb___341067609742207438_69941629868780'

This is the method that does the search:

     def index
    if  params[:search].present?
      @search = params[:search]
      @locations = Location.where('id LIKE ? OR user_id LIKE ?', "%#{@search}%", "%#{@search}%") 
    else 
       @locations = Location.all
    end
  end

1 Answer 1

1

Here are some confusion. You mentioned Postgres on Heroku in title while MySql in description.

I assumed you are using Postgres to write below code.

In case if you are using MySql then use LIKE in given code.

@locations = Location.where("id ILIKE :search OR user_id ILIKE :search", search: "%#{@search}%")

Let me know if you find this helpful!!!

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, because since I've deployed in Heroku I had to use Postres but on my PC I was using MySQL to develop, either way, I'll test and give a feedback!
So I tried as you told but still getting error, not quite the same tho, I'm trying to figure it out, but it was helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.