Skip to content

Suggestions to authorize data sent from view #222

Answered by palkan
stephannv asked this question in Q&A
Discussion options

You must be logged in to vote

I usually use scoping to verify associated record ids. Something like this:

def record_params
  params.permit(:bank_account_id).tap do |permitted|
    permitted[:bank_account_id] = authorized(BankAccount).find_by(id: permitted[:bank_account_id])&.id
  end
end

If bank_account_id has been compromised, we do not pass to the operation (Records::Create.call), and that's the responsibility of the operation to raise a validation exception (missing parameter).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stephannv
Comment options

Answer selected by stephannv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants