Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

NoMethodError: undefined method `[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>

Đang mở
#206 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rails, ruby
Lĩnh vực
api, backend

Hướng nghiên cứu

Start in lib/grape_entity/exposure/base.rb at Exposure::Base#serializable_value and reproduce the failure with the Post, Author, and PostEntity example in the issue. Compare the object, array, and hash serialization paths and the linked ActiveRecord serializable_hash behavior. Done means the example no longer raises NoMethodError and the corrected behavior is covered by a regression test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

feature question

When you have an entity which exposes an ActiveRecord belongs_to without a :using option, then serializable_hash is called with a Grape::Entity::Options object.

But serializable_hash clones the object and then tries to set :except on it. (It sets default :except to an empty array see here.) This causes the exception:

NoMethodError: undefined method '[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>

Not too big of a problem, it was just a forgotten :using, but it was very confusing.
Also depending on whether it's an object, array or hash, serializable_hash is called with or without options.

I'm talking about the code in Grape::Entity::Exposure::Base#serializable_value.

Should the options even be passed to serializable_hash at all? Or should []= be implemented?
This did work up until this commit btw.

Example to reproduce:

class Author < ActiveRecord::Base
end

class Post < ActiveRecord::Base
  belongs_to :author
end

class PostEntity < Grape::Entity
  expose :author # notice missing :using
end

PostEntity.represent(Post.first).as_json # => NoMethodError
Ngôn ngữ chính
Ruby
Star
730
Fork
155
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby-grape/grape-entity

Tất cả issue của ruby-grape/grape-entity

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.