-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work with Rails 7 api_only = true #532
Comments
I'm using Rails 7 in api_only mode as well and everything works fine. As far as I see it, the problem here is render json: {foo: 'bar'} jBuilder views behave just like normal ones, so e.g. for an def index
@practice_tests = PracticeTest.all
end is sufficient. I hope this helps a little. |
Got it. Thank you!
…On Mar 1, 2022 at 1:07:23 PM, Stefan Exner ***@***.***> wrote:
I'm using Rails 7 in api_only mode as well and everything works fine.
As far as I see it, the problem here is render json: which basically just
calls @practice_tests.as_json and doesn't render an actual view. It's the
same as if calling
render json: {foo: 'bar'}
jBuilder views behave just like normal ones, so e.g. for an index action,
it will search for a index.json.jbuilder template which you don't have to
specify yourself. In this case
def index
@practice_tests = PracticeTest.allend
is sufficient.
I hope this helps a little.
—
Reply to this email directly, view it on GitHub
<#532 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAATIARGJS7SLHPHE7CM27DU5ZMFXANCNFSM5PGA55TQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Rails 6 has the same issue. What configuration does Rails need to enable native JBuilder for JSON? |
I just finished an upgrade to 6.1.6.1 (from 5.2.8) and am trying to fix all of the numerous:
Issues being thrown by rspec and I cannot seem to find an answer about this that works. |
Sorry for the second reply, but for what it's worth, I got the DEPRECATION warning taken care of by changing my calls to
to:
And you can even include |
Rails 5 has the same issue -- but I am not sure how far back this gem is suppose to support. |
Rails 7 (without api_only = true) does not have the same issue. Works well out of the box when requesting an resource's
|
Clean install of a new Rails 7 api_only app:
config.api_only = true
Added the jbuilder gem and generated a scaffold that has this line:
render json: @practice_tests, status: :ok
But the jbuilder files are not rendered - simply ignored. I believe it has to do with the views not being loaded in Rails 7 api only mode. Any thoughts on how to get this to work?
The text was updated successfully, but these errors were encountered: