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

Migrating to Rails 5 - Rabl returning Active Record object #715

Open
frank184 opened this issue Jul 20, 2018 · 0 comments
Open

Migrating to Rails 5 - Rabl returning Active Record object #715

frank184 opened this issue Jul 20, 2018 · 0 comments

Comments

@frank184
Copy link

frank184 commented Jul 20, 2018

We are migrating to Ruby on Rails 5, and upgrading to rabl >= 0.13.

Everything looks good except this one request that is returning a stringyfied object instead of a view.

JSON::ParserError:
       784: unexpected token at '#<ReferenceNumber::ActiveRecord_Relation:0x00007fda690fedd0>'

We are using grape and grape-rabl and the request looks like so:

desc 'Deletes a reference ID'
params do
  requires :device_id, type: String, desc: 'Device Identifier.'
  requires :cardnumber, type: String, desc: 'Card number.'
  requires :reference_number, type: String, desc: 'Reference ID'
end
delete '/reference_numbers', rabl: 'devices/cardholder/reference_numbers', http_codes: [
  [...business errors...]
  [401, 'Unauthorized'],
  [403, 'Forbidden - trying to access resource that is not authorized for this merchant']
] do
    ... business logic ...
    @reference_numbers = ReferenceNumber.by_card_number(params[:cardnumber])
    	.by_participating_businesses(@device.participating_business)
end

The rabl view file looks like this:

node(:reference_numbers) do
  @reference_numbers.map do |reference_number|
    {
      number: reference_number.number,
      business: reference_number.participating_business.name
    }
  end
end

Where @reference_numbers is equal to an empty ActiveRecord_Relation, the view returns that object.

Whenever @reference_numbers has results then everything works properly.

Might not be understanding the changes between Rabl 0.12 and 0.13, if anyone understands whats going on or has any suggestions, please let me know!

EDIT

I've tried testing very similar requests and to no avail cannot reproduce this issue.

Then I tried commenting out the @reference_numbers = line and the rabl file is rendered.

Strange since if it were that line, then you'd expect the same kind of issue throughout where this line appears, but this is not the case.

@frank184 frank184 reopened this Jul 20, 2018
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