Skip to content
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

json.array! @reports, :id, :count always give me all the attributes.[Not an issue] #515

Closed
gazeldx opened this issue Nov 17, 2021 · 1 comment

Comments

@gazeldx
Copy link

gazeldx commented Nov 17, 2021

Env: jbuilder (2.11.3), Rails 6.1.4.1.

Controller:

def index
    @reports = Report.all.order(:id)
    respond_with @reports
end

index.json.jbuilder:

json.array! @reports, :id, :count
  • Expected result: Only attributes :id and :count were generated in the json result, like:
[{"id":1,"count":502},
{"id":2,"count":508}]
  • Actual result: All the attributes were generated in the json result, like:
[{"id":1,"count":502,"fee":59,"duration":1098,"customerid":"65102","customername":"测试数据1"},
{"id":2,"count":508,"fee":87,"duration":2391,"customerid":"65103","customername":"测试数据2"}]
@gazeldx gazeldx closed this as completed Nov 17, 2021
@gazeldx gazeldx changed the title json.array! @reports, :id, :count always give me all the attributes. json.array! @reports, :id, :count always give me all the attributes.[Not an issue] Nov 17, 2021
@gazeldx
Copy link
Author

gazeldx commented Nov 17, 2021

This is caused by my view didn't follow Rails' naming convention. Not an issue of jBuilder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant