Skip to content

Instantly share code, notes, and snippets.

@smd686s
Last active October 27, 2016 02:16
Show Gist options
  • Save smd686s/6320643 to your computer and use it in GitHub Desktop.
Save smd686s/6320643 to your computer and use it in GitHub Desktop.
Use Strong Parameters in a Grape API without Rails
require 'rack/test'
require 'action_controller/metal/strong_parameters'
# https://github.com/rails/rails/blob/master/actionpack/test/controller/parameters/parameters_require_test.rb
module Application
class API < Grape::API
helpers do
def item_params
ActionController::Parameters.new(params).require(:item).permit(:attribute)
end
end
desc "Create an item."
post :items do
Item.new item_params
end
end
end
gem "actionpack", "~> 4.0.0"
@BGuimberteau
Copy link

our solution without need to include 'action_controller/metal/strong_parameters'

https://gist.github.com/BGuimberteau/4da1ab54e576121edde5

@vyorkin
Copy link

vyorkin commented Dec 30, 2015

if I'm on a pure Rack, why do I ever need actionpack? https://github.com/ruby-grape/grape/blob/master/grape.gemspec#L15

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