Skip to content

Conversation

@tiagopog
Copy link
Owner

@tiagopog tiagopog commented Jul 3, 2016

Implements #22 and fix #21

Details

Example

Use resource_params helper when you need to get the permitted params from params['data']['attributes']:

class UsersController < BaseController
  # POST /users
  def create
    user = User.new(resource_params)
    if user.save
      jsonapi_render json: user, status: :created
    else
      jsonapi_render_errors json: user
    end
  end
end

Use relationship_params helper when you need to get ids from params['relationships']:

class PostsController < BaseController
  # POST /posts
  def create
    post = Post.new(post_params)
    if post.save
      jsonapi_render json: post, status: :created
    else
      jsonapi_render_errors json: post
    end
  end

  private

  def post_params
    resource_params.merge(user_id: relationship_params[:author])
  end
end

@tiagopog tiagopog self-assigned this Jul 3, 2016
@tiagopog
Copy link
Owner Author

tiagopog commented Jul 4, 2016

With the inclusion of JSONAPI::Utils::Request#jsonapi_request_handling method, this will also help fixing the #21.

@tiagopog tiagopog closed this Jul 4, 2016
@tiagopog tiagopog deleted the feature/params_helpers branch July 4, 2016 14:28
@tiagopog tiagopog restored the feature/params_helpers branch July 4, 2016 15:03
@tiagopog tiagopog deleted the feature/params_helpers branch July 4, 2016 15:03
@tiagopog
Copy link
Owner Author

tiagopog commented Jul 4, 2016

Implementation packaged in v0.4.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inclusion of JSONAPI::Utils in a specific controller obfuscates errors

2 participants