Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#206 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
rails, ruby
領域
api, backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Ruby
スター
730
フォーク
155
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby-grape/grape-entity のほかの issue

ruby-grape/grape-entity の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。