Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 30 15:31
    beauby commented #7
  • Oct 29 19:56
    deividaspetraitis commented #7
  • Oct 17 04:22
    cedm commented #22
  • Oct 10 11:51
    faissalMT edited #113
  • Oct 10 11:50
    faissalMT opened #113
  • Oct 05 17:53
    benlieb opened #22
  • Sep 24 00:27
    cassidycodes edited #112
  • Sep 24 00:27
    cassidycodes edited #112
  • Sep 24 00:27
    cassidycodes opened #112
  • Sep 18 14:33
    drbarto opened #111
  • Sep 15 09:10

    dawidof on master

    resources_processor: speed up r… Merge pull request #40 from alc… (compare)

  • Sep 15 09:10
    dawidof closed #40
  • Sep 11 17:20
    gmkohler commented #106
  • Sep 09 21:24
    alchimere synchronize #40
  • Sep 09 20:27
    alchimere edited #40
  • Sep 09 20:26
    alchimere edited #40
  • Sep 09 20:26
    beauby commented #40
  • Sep 09 20:24
    alchimere opened #40
  • Sep 09 13:49
    amaierhofer commented #105
  • Sep 07 18:37
    JoeWoodward commented #106
Tom Simnett
@simmerz
Does anyone have a good way to get a dot formation include, and convert it to an array to pass to ActiveRecord .includes()?
K Fitz
@kfitzvineti
I'm sure this has been asked before, but I can't find it in history. Is there a way to specify an ActiveResource scope (such as something like :active) in a controller for an attribute of an included relation?

e.g.

render jsonapi: procedure,
           class: {
             T: SerializableT,
           },
           include: [
             { t: %i(foo) },
           ],

Where I only want foo.active?

Davi Koscianski Vidal
@davividal
Hi all. I need to be able to generate a JSON like { "name": "foo", "age": "30" } -- it is a legacy API. The software I'm replacing already outputs JSON like that and I have clients expecting that JSON. I want to move to json-api, but now is not the right time.
So, is it possible to setup jsonapi-rb to don't use jsonapi standard?
or am I just being stupid to ask that? :)
Little background: I could use simple to_json, but it is very easy to forget or to make mistakes. So I really want to use a serializer. I could use any other serializer (like jbuilder), but I really want to be able to use jsonapi in the upcoming months and I really like the jsonapi-rb approach.
So, the best scenario would be if jsonapi-rb had some kind of config.enable_dum_mode = true . :)
Tom Simnett
@simmerz
@davividal are you usng Rails? If so, you can just use active_model_serializer in attribute mode, and then use the content type header to respond with jsonapi as required.
Lucas Hosseini
@beauby
Dear @/all , jsonapi-rb finally has a new maintainer. Please welcome @dawidof 🎉
L. Preston Sego III
@NullVoxPopuli
yay!
Dmytro Koval
@dawidof
It is my pleasure
David Roy
@code-bunny

I am trying to do a few things here that just aren't working as I expect and could do with a pointer in the right direction.

  deserializable_resource :user, only: [:create, :update] do
    key_format(&:underscore)
    id
    attributes :'first-name', :'last-name'
    has_one :skill_level
  end

    def user_params
      params.require(:user).permit!
    rescue ActionController::ParameterMissing
      {}
    end

In my controller I am deserialising a user that has a relation called skill-level, I am expecting in my user_params to respond to user_params[:skill_level] or :skill_level_attributes, however I seem to need to access this via :relationships. In addition I don't seem to be able to access the included part of my document when trying to post a compound document.

David Roy
@code-bunny
Disregard the first part of my last post, my relationships where daft but I would still like to consume the included data of a relationship in a compound document
Sudeep Tarlekar
@sudeep-vineti

Hi, I am new to JSONAPI, I am trying to render a plain ruby hash with JSONAPI
here is example controller like

class ConfigurationController < ApplicationController
def index
render jsonapi: { token: '#token' }
end

and serializer for same as

class ConfigurationSerializer < ActiveModel::Serializer
attributes :token
end

I am getting error while sending json response using JSONAPI, can anyone tell me how can I render a hash using a JSONAPI?
I tried passing a class as class: ConfigurationSerializer, but ended up getting error.

Thanks in advance

Gregory M Kohler
@gmkohler
try class: { Hash => ConfigurationSerializer }
class is a hash from ClassToBeSerialized => Serializer which by default will be Class => SerializableClass https://github.com/jsonapi-rb/jsonapi-rails/blob/7a17c8a0c04d78d29abecdff0062b429d14dda1e/lib/generators/jsonapi/initializer/templates/initializer.rb#L3-L7
@sudeep-vineti
Linus Sellberg
@yxhuvud
How do I turn off logging? I don't want a bunch of crap in the terminal when running specs.
Linus Sellberg
@yxhuvud
Also, can I turn off the meta: { jsonapi"=>{"version"=>"1.0"}} somehow?
Ah, by using a renderer manually.
how
@hellekin_gitlab
@beauby great news! Thank you @dawidof!
Gregory M Kohler
@gmkohler
@yxhuvud try adding this to your initializers/jsonapi.rb file:
  config.logger = Logger.new("/dev/null")
Linus Sellberg
@yxhuvud
Thanks, though I ended up using the renderer directly instead. It solved both my issues :)
Karol Karwacki
@karwank
Hi everybody, is anyone here ?
I'd like to ask how to fix "No serializable class defined for Resource"
Gregory M Kohler
@gmkohler
Do you have a serializer defined for every class being serialized in the payload? For Namespace::ClassName, you need a Namespace::SerializableClassName
@karwank ^
Linus Sellberg
@yxhuvud
You can also define a lookup table with the class option. I couldn't find a way to define those lookup tables in the serializers themselves though, so it looks like it has to be in every use place.
Karol Karwacki
@karwank
what if I wanted to have two different serializers for two different versions of API ?
for the same resource
Matt Holtom
@mattholtom

Hello everyone, new to the community. I've done some research in the docs and various repos under jsonapi-rb organization, but I can't find an example of accepts_nested_attributes_for usage with a 'bulk' document. I think the JSONAPI spec may consider support for bulk updates/creates an extension, and it may have even been scrapped. I can see various PR's throughout the repos trying to implement this, but none which have been merged.

Has anyone else deserialized nested attributes from JSON-API format to a hash that rails can digest? Currently we have pretty standard rails controllers that accept form data from traditional ERB views/ form_for objects (cocoon actually) i.e.:

def update
    if parent.update_attributes(update_params)
      redirect_to next_url
    else
      render :edit
    end
  end

def update_params
    params.require(:parent).permit(:parent_attr_1, children_attributes: [:id, :description, :first_name,  :_destroy])
  end

And we seek to convert them to accepting JSON-API formatted json. Something like this:

# in controller
  deserializable_resource :children, class: DeserializableChild, only: [:update]

# in deserializer
class DeserializableChild < JSONAPI::Deserializable::Resource
  key_format(&:underscore)
  attributes
end

So my question is, is there a strategy I should follow? Has anyone done this in the past? Or is there another library that supports this out of the box? Our entire app is these nested forms, so it would be worth switching to AMS if they do support this officially. Thanks in advance for your insights!

Matthew Mongeau
@halogenandtoast
If attribute names are not camelcased, is there something I have setup incorrectly?
Matthew Mongeau
@halogenandtoast
Looks like I can do something like
class SerializableResource < JSONAPI::Serializable::Resource
  extend JSONAPI::Serializable::Resource::KeyFormat
  key_format -> (key) { key.to_s.camelize(:lower) }
end
nuheluxulu
@nuheluxulu
if one does a has_many, is it supposed to give the attributes of comments (assuming example)
Linus Sellberg
@yxhuvud
You need to specify that the association should be included when generating the response, too.
if you are running the controller integrations, that is probably done by adding include=comments to the request.
Psy-Q
@psy-q
is there something that helps me set up the relationships when i PATCH a resource to add/remove some related records?
oooh, there seems to be some magic going on, it seems to have parsed the related stuff into some kind of Ruby data structure
including guessing that "type": "database_users" would resolve to DatabaseUser and database_user_ids. so something is going on there
Psy-Q
@psy-q
just wonder what's the correct way to get at this data
it parses params to this:
=> <ActionController::Parameters {"_jsonapi"=><ActionController::Parameters {"data"=>{"relationships"=>{"database_users"=>{"data"=>[{"type"=>"database_users", "id"=>"1"}]}}, "type"=>"databases", "id"=>2}} permitted: false>, "format"=>:json, "controller"=>"databases", "action"=>"update", "id"=>"2", "database"=>{"type"=>"databases", "id"=>2, "database_user_ids"=>["1"], "database_user_types"=>["DatabaseUser"]}} permitted: false>
Psy-Q
@psy-q
which looks like the right kind of magic, so is it safe to get the IDs from params[:database][:database_user_ids]?
Psy-Q
@psy-q
i tried it with database.database_user_ids = params[:database][:database_user_ids] and it seems to work. so even if this isn't the "official" way, maybe it's useful
Linus Sellberg
@yxhuvud
Is it possible to make the api NOT emit {"meta"=>{"included"=>false}} for relationships that isn't included? It is very redundant and makes it more of a pain to generate documentation of how the responses to requests will look like.
Linus Sellberg
@yxhuvud
looks at the code used to generate it. No, it seems there are no option to not generate the bloat in question.