This is my routes.rb
namespace :api do
get 'suggestions/jobs', to: "suggestions#jobs"
end
My controller
class Api::SuggestionsController < ApplicationController
def jobs
@jobs = Job.job_title_search(params[:q]) #.select(:title, :label).distinct
if @jobs.present?
render json: @jobs, status: :ok
else
render json: "Not Found", status: :ok
end
end
end
and model
def self.job_title_search(q)
where('title LIKE ?', "%#{q}%").select(:title, :label).distinct
end
in the development environment like localhost:3000/api/suggestions/jobs?q=dev
the data sample is
[
{"id":null,"title":"React Native Developer","label":"Top label job"},
{"id":null,"title":"Android Developer","label":"Top label job"},
{"id":null,"title":"Business Development Representative","label":"Mid label job"},
{"id":null,"title":"Node.js Developer","label":"Top label job"}
]
that means it's working, but while I pushed into the Heroku then like example.herokuapp.com/api/suggestions/jobs?q=dev
it's showing
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I know there is "Not Found" like the code is
render json: "Not Found", status: :ok
My question is why same code is not working on Heroku? and What can I do for this?
the database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: my_project_production
username: my_project
password: <%= ENV['MY_PROJECT_DATABASE_PASSWORD'] %>
Any help appriciated.
Thanks