Questions tagged [grape-entity]

grape-entity - Entities - a simple Facade to use with your models and API - extracted from Grape.

grape-entity - Entities - a simple Facade to use with your models and API - extracted from Grape.

https://github.com/intridea/grape-entity

51 questions
0
votes
1 answer

How to fix JSON string in the response in Grape Entity

I'm trying to expose a column which is saved in the DB as a JSON string. But it showed as just string. Any help would be appreciated. Entity sample: class Entity < Grape::Entity expose :id expose :name expose :credentials # this is…
0
votes
1 answer

How can I return polymorphic data with Grape Enttity and Swagger?

I have a polymorphic tag and want to search ambigous items by this tag. How can I return this whith Grape Entity? class Tag < ActiveRecord::Base belongs_to :taggable, polymorphic: true end class Article < ActiveRecord::Base has_many :tags, as:…
Martin M
  • 8,430
  • 2
  • 35
  • 53
0
votes
1 answer

Grape Entity expose to delegate/forward to other object

When using Grape Entity, sometimes we want to expose a few fields from an inner/related object. We can simply do this by: expose(:bar) { |entity| entity.foo.bar } However if many fields needs this treatment, this can get very repetitive. Is there a…
lulalala
  • 17,572
  • 15
  • 110
  • 169
0
votes
1 answer

How to use grape entity based on value of a field?

Anyone worked on Grape & Grape entity i have an issue. db: Mongoid I have two models 1. User 2. Answers every user have package_type: 1 or 2 or 3 and every answer also have package type in array but of single value. LIKE [1] or [2] or [3]. I want…
Jasjeet Singh
  • 332
  • 1
  • 6
  • 18
0
votes
0 answers

Grape entity empty active record array

I am using grape API and returning response using grape entity framework. get '/' do users = User.all present users, with: API::Entities::UserInfo end module API module Entities class UserInfo < Grape::Entity expose 'UserInfo' do …
Sam
  • 5,040
  • 12
  • 43
  • 95
0
votes
1 answer

Apply alias for loop in grape entity

I would like to get the following JSON. [{"Product":{"CountryName":4848, }},{"Product":{"CountryName":700}] module API module Entities class Example < Grape::Entity expose(:product) do expose(:country_name) do |product,…
Sam
  • 5,040
  • 12
  • 43
  • 95
0
votes
1 answer

Grape::Entities, how to expose property only for writing

how can i expose revision property of VehicleDetails that will not appear on GET request, but will be obligatory on PATCH/POST (only writing operations)? class VehicleDetails < Grape::Entity expose :id expose :name expose :type expose…
Kapitula Alexey
  • 380
  • 4
  • 15
0
votes
0 answers

Automagically creating API endpoints and their basic swagger documentation

Rails is so magical that I need help from someone who knows a little better than I do. Since I have a lot of crud API basic endpoints repeated over and over I decided to automate their creations (see my final post in the following github issue). For…
Francesco Meli
  • 2,484
  • 2
  • 21
  • 52
0
votes
1 answer

Inheriting class definition from parent class

I am building Grape Entities inside my Rails models as described here: https://github.com/ruby-grape/grape-entity#entity-organization Currently I am creating default values automatically, based on the column hash of the model itself. So I have a…
Francesco Meli
  • 2,484
  • 2
  • 21
  • 52
0
votes
3 answers

How to define a dynamic key in grape-entity gem?

Lets say I have a User model and I am exposing User object via Grape::Entity. So in here I want to define a dynamic key which name and its value will be based on other keys(id, name, email) value. module API module Entities class User <…
Junan Chakma
  • 651
  • 7
  • 14
0
votes
0 answers

Rails LEFT OUTER JOIN Index request with Grape Entity

I am currently using Grape API alongside Rails for our API (Postgresql for the DB). I'm a Junior Dev working full time as a Full Stack Developer so I apologise with my lack of experience with explaining this question. Currently I am trying to…
Alan Dragicevich
  • 391
  • 2
  • 5
  • 13
0
votes
1 answer

How can I custom format an attribute using Ruby Grape Entity?

I have an attribute price in my model, and currently it is being formatted in scientific notation, and I would rather display in decimal notation. ruby-grape suggests the following code for custom formatting a field: class ExampleEntity <…
André Pontes
  • 447
  • 1
  • 4
  • 13
0
votes
1 answer

Invalid constant API:: with grape and grape-entity

I'm trying to use grape-entity and I'm having trouble with the name-space of my entity class but I cannot figure why. I have this grape-entity class : # app/controllers/api/v1/entities/vehicules.rb module API module V1 module Entities …
Alain ANDRE
  • 305
  • 1
  • 13
0
votes
1 answer

Grape: How to remove the extra root element from XML response when exposing a collection with grape-entity?

I'm using grape (0.14.0) with grape-entity (0.5.0) to create a XML API within my Rails (4.2.5) app. Whenever I specify an explicit root element within a Grape::Entity class the XML response gets wrapped in an unwanted root element . How can I…
Denny
  • 79
  • 4
0
votes
1 answer

ruby grape post method insert multiple rows

How to post multiple rows into DB using ruby Grape. For example when testing with CURL this is working fine curl -H "Content-Type: application/json" -X POST \ -d '{"name": "test", "age": "22"}' http://localhost:3000/students But this is not…
ejo
  • 446
  • 1
  • 9
  • 23