Description
I don't have a solid mental model for what's happening when I'm trying to set a class -> serializable class mapping.
I've got two classes:
class Relationship < ApplicationRecord
# relationship stuff. baggage, if you will.
end
# then, nested in app/models/relationships:
class Relationships::Approve < Relationship
# approval related things, so all that logic is only here
end
I've got a SerializableRelationship
class that's working. I'd like to reuse that with these subclasses.
class Api::Relationships::ApprovesController < Api::ApiController
before_action :set_relationship
def update
if @relationship.update(status: "approved", action_user: current_user)
render jsonapi: @relationship
else
render jsonapi_errors: @relationship.errors
end
end
private
def set_relationship
@relationship = Relationships::Approve.find(params[:id])
end
end
How do I:
- set this option inside my controller action?
- set this option at the controller wide level? (aka this )
- application-wide level (in the initializer)?
I know that, once I get it, it'll probably be an "ohhhh" moment. I conceptually understand it's a big hash that makes certain keys to certain other classes that serialize those things. But I need to see an example, and get details, because I don't understand:
- what does the key need to be?
- what does the value need to be?
- are modifications made to the things I pass in?
I've been guessing things and not getting feedback I know how to understand from the errors.
I think this would make some great addition to the docs! I'll check back in when I figure it out, and maybe PR in some updates if you're ok with that.