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

Help with endpoint for a non-ActiveRecord model without a database table

オープン
#1,092 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
rails, ruby
領域
api, backend

調査の方向性

CalendarEventモデルの例とApi::V3::CalendarEventsControllerから始め、次にJSONAPI::ResourceSerializerがマッピングされたActiveModel配列をどのように処理するかを追跡します。204 No Contentレスポンスを再現し、ActiveRecordではないモデルに対するresourceとserializerの挙動を調査します。サポートされているシリアライズ方法を特定するか、必要な統合変更を文書化できれば完了です。

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

説明

I have a non-ActiveRercord model without a database table I am trying to create an API endpoint for. The data for this model is populated dynamically with custom SQL and provides generic relations to real ActiveRecords.

Because of all the magic happening with JSONAPI Resources I am having a hard time serializing the array of ActiveModels successfully. Am wondering what the best approach for this might be? I've tried some monkey patching without success and would appreciate guidance

model example

class CalendarEvent
  include ActiveModel::Model

  attr_accessor(
    :id,
    :title,
    # etc etc
  )

  def self.modelize(record)
    return CalendarEvent.new(record)
  end

  def self.records(person_id, start_date, end_date, options = {})
    sql = "select 'some custom sql' from various_table where serious_magic_happens"
    records = ActiveRecord::Base.connection.execute(sql)
    records = records.map{ |r| self.modelize(r) } # returns an Array of CalendarEvent::Class
  end

end

controller attempt

class Api::V3::CalendarEventsController < Api::V3::ApiController

  def index
    records = CalendarEvent.records(1686, '2017-07-01', '2017-07-31')
    resources = records.map { |r| Api::V3::CalendarEventResource.new(r, nil) }
    JSONAPI::ResourceSerializer.new(Api::V3::CalendarEventResource).serialize_to_hash(resources)
  end

end

The above controller returns a 204 No Content even though I am passing serialize_to_hash an array ... am I misunderstanding how this should work ? Or is there a better way?

Thanks!

主要言語
Ruby
スター
2.3k
フォーク
546
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

JSONAPI-Resources/jsonapi-resources のほかの issue

JSONAPI-Resources/jsonapi-resources の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

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

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