Skip to content

Strategies: Use with strong_parameters

haihappen edited this page Aug 8, 2012 · 9 revisions

To use with the strong_parameters plugin, add a strategy:

class StrongParametersStrategy < DecentExposure::ActiveRecordWithEagerAttributesStrategy
  def attributes
    get? ? super : controller.send(:"#{name.singularize}_params")
  end
end

You can then use the strategy in your controller:

class UserController < ApplicationController
  expose(:users)
  expose(:user, strategy: StrongParametersStrategy)
  
  private

  # Name a private method #{exposure_name}_params
  def user_params
    params.require(:user).permit(:name, :age)
  end
end