Answer the question
In order to leave comments, you need to log in
Why doesn't the find_by_slug method in ROR work on the server via PUMA?
I'm making an API for GET requests.
The task was to open a specific page not by ID, but by a specific number corresponding to a column in the database.
The following scheme works correctly on the local computer.
After deploying to the server and trying to open the page by some_id_number, I get:
Completed 500 Internal Server Error in 13ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `find_by_slug' for Class:.....
Did you mean?
find_by_sql some_id_number everything works, it finds the correct page.
On the server, it gives the same undefined method.
The database on the local and on the production PostgreSQL are of the same versions.
Tell me, what could be the reason?
Controller:
module Api
module V1
class PagesController < ApplicationController
def show
@page = Page.find_by_slug(params[:some_id_number])
render json: { status: 'SUCCESS', message: 'loaded', somenumber: @page.some_id_number, pid: @page.id }, status: :ok
end
end
end
end
namespace :api do
namespace :v1 do
resources :pages, only: :show, param: :some_id_number
end
end
Answer the question
In order to leave comments, you need to log in
Found a solution. Might be useful to someone:
module Api
module V1
class PagesController < ApplicationController
def show
@page = Page.find_by(some_id_number: params[:some_id_number])
render json: { status: 'SUCCESS', message: 'loaded', somenumber: @page.some_id_number, pid: @page.id }, status: :ok
end
end
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question