I'am trying rails-api gem with jbuilder and i can't seem to make it work
Here is a sample of my rails-api controller / jbuilder views
Gemfile
gem 'jbuilder'
Controller app/controller/users_controller.rb
def show
@user = User.find_by(id: params[:id])
end
View app/views/users/show.json.builder
json.content format_content(@user.id)
According to the Jbuilder documentation this should work fine but still nothing is returned.
Thanks for the help!
I know that the original issue had probably been resolved. Nevertheless I had the same issue and finally found an answer.
Since rails-api is stripped down version of rails some functionalities are missing (in this case implicit rendaring of views) and we need to add them explicitly.
Simplest solution is to add ActionController::ImplicitRender to ApplicationController
# app/controllers/application_controller.rb
class ApplicationController < ActionController::API
include ActionController::ImplicitRender
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With