by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 06 00:46
    caomania commented #79
  • Jul 31 10:20
    helmiItsavirus edited #119
  • Jul 31 10:20
    helmiItsavirus opened #119
  • Jul 14 16:16
    mohitagarwal18 commented #114
  • Jul 14 16:12
    mohitagarwal18 commented #114
  • Jun 24 08:50
    addywaddy commented #117
  • Jun 23 06:18
    wuarmin commented #107
  • Jun 23 06:18
    wuarmin commented #107
  • Jun 21 16:29
    ClayShentrup commented #107
  • Jun 21 06:49
    wuarmin commented #107
  • Jun 21 06:46
    wuarmin commented #107
  • Jun 21 06:44
    wuarmin commented #107
  • Jun 20 05:58
    ClayShentrup commented #107
  • Jun 20 05:53
    ClayShentrup commented #107
  • Jun 20 05:53
    ClayShentrup commented #107
  • Jun 20 05:51
    ClayShentrup commented #107
  • Jun 19 13:52
    matteo95g opened #118
  • Jun 13 11:22
    shushugah closed #116
  • Jun 13 11:22
    shushugah commented #116
  • Jun 13 11:21
    shushugah opened #117
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.
mathewbaltes
@mathewbaltes
Hi JSONApi-eers. Not sure if anyone is actually in this chat.
I was working with dynamoid and wanted to use the renderer out of the box. Enumerator::Lazy supports :to_a but does not implement :to_ary
Linus Sellberg
@yxhuvud
Because all objects respond to to_a, so using to_a would make the if statement pretty pointless.
pmokariya
@pmokariya
Is it possible to remove ID from the SerializableCLASSNAME ?
I need json response like below
{
"data": {
"type": "articles",
I don't want this ID here"id": "1",
"attributes": {
// ... this article's attributes
},
}
Francesco Belladonna
@Fire-Dragon-DoL
@pmokariya I doubt it, the id is required as part of the JSONAPI specs
is there some kind of caching support for rails? I see some parameters but struggling to identify how to use it
Alex Oliveira
@kurko
I've been away from the community for a while, but this month I'm going to pick a deserializer. People who are using jsonapi-rb, are you enjoying it? Any outstanding problems?
Psy-Q
@psy-q
it's working OK for me and after i found out that there is certain magic involved in deserializing relationships, it seems it does all i need. will upgrade my stack at some point and hope it still works then
Alex Oliveira
@kurko
Nice. Thanks @psy-q. The relationships part is trickiest I think, so good to know. Did you have to do any hacks/acrobatics to make it work?
bnpIng
@bnping
what is the diff between include and fields ?
include: [:author, comments: [:author]],
fields: { users: [:name, :email] },
Pavel Argentov
@argent-smith
Hi ppl. I've got an AR model named Instance and a serializer named SerializableInstance with some stuff in it. When I do render jsonapi: instance in my controller, it ignores the serializer: the output looks just like render json: instance. What could be wrong?
also, when I use class: { Instance: SerializableInstance } parameter, it doesn't render anything from the serializer, too
Pavel Argentov
@argent-smith
Found the reason: rendering was overridden in some legacy initializer code.
bnpIng
@bnping
how jsonapi_filter works ?
RobOldCodes
@RobOldCodes_twitter
Hi, I wasn't sure how actively the project is maintained so it's great to see people talking in here!
I'm just starting out on a new project- everything about the library looks great except that there are un-merged PRs that have been there a while
RobOldCodes
@RobOldCodes_twitter
Can people recommend this library for production use? Is it looking for new maintainers?
Amit Suryavanshi
@amitTheSongadya_twitter
I am trying to find specifications to create resources with ruby Duration type. Anyone has any recommendations ? Thanks.
Heinrich Klobuczek
@klobuczek
If there is nothing implemented so far I would use https://en.wikipedia.org/wiki/ISO_8601#Durations
Amit Suryavanshi
@amitTheSongadya_twitter
Okay, Thanks. That is how it stored in DB "P0M7DT0S"