Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserialize_jsonapi not found on controller #10

Closed
bastianlb opened this issue Apr 20, 2017 · 3 comments
Closed

deserialize_jsonapi not found on controller #10

bastianlb opened this issue Apr 20, 2017 · 3 comments

Comments

@bastianlb
Copy link

bastianlb commented Apr 20, 2017

I'm having trouble during a patch with strong_resources. The guides say I should add before_action :deserialize_jsonapi!, only: [:create, :update] in order for puts/creates to work properly (makes sense). However this method doesn't seem to exist, and I didn't find it in the code.

ERROR: NoMethodError: undefined method `deserialize_jsonapi!' for #<UsersController:0x007fb548ebd4f8>
Did you mean?  deserialized_params

Is this due to out of date docs? Thanks.

@richmolj
Copy link
Contributor

Yes, this is my fault for not keeping the docs up to date. I've been working on the client-side recently - now that that's wrapped up we can focus on maintenance and you hopefully won't see issues like this again :)

I'll have everything updated (with a full-stack sample application) this weekend, but for now, here's an example controller. Mostly just replace the deserialization with apply_strong_params:

class EmployeesController < ApplicationController
  jsonapi resource: EmployeeResource

  strong_resource :employee do
    has_many :positions, destroy: true do
      belongs_to :department, destroy: true
    end
  end

  before_action :apply_strong_params, only: [:create, :update]

  def create
    employee, success = jsonapi_create.to_a

    if success
      render_jsonapi(employee, scope: false)
    else
      render_errors_for(employee)
    end
  end

  def update
    employee, success = jsonapi_update.to_a

    if success
      render_jsonapi(employee, scope: false)
    else
      render_errors_for(employee)
    end
  end

  def destroy
    employee = Employee.find(params[:id])
    employee.destroy
    render_jsonapi(employee, scope: false)
  end
end

@richmolj
Copy link
Contributor

For an up-to-date sample application and in-depth examples: https://gist.github.com/richmolj/c7f1adca75f614bb71b27f259ff3c37a

@richmolj
Copy link
Contributor

@BastianL main documentation site is updated, please confirm this all now makes sense 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants