ruby-grape / ruby-grape/grape

Allow type to be a model

Open
#597 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss! feature request
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

I don't have an idea for the best syntax but I find myself loading models from the params hash a lot. What if you were able to do something like this?

params do
    requires :user_id, identifies: User
end
get 'users/:user_id' do
   params[:user] # params calls User.find internally and raises the appropriate error if nothing is found
end

Thoughts?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named. Start by reviewing how Grape parameter declarations and params access currently work, then determine the intended syntax, model lookup behavior, and error handling. Done would require an agreed API design and tests covering successful lookup and missing models.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.