Skip to content

Instantly share code, notes, and snippets.

@elsapet
Last active September 28, 2015 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elsapet/40e76ff048c640edbf43 to your computer and use it in GitHub Desktop.
Save elsapet/40e76ff048c640edbf43 to your computer and use it in GitHub Desktop.
class AnimalsController < ApplicationController
inherit_resources
..
protected
def build_resource_params
animal_params = params.fetch(:animal, {}).permit(:name, :age, :family)
[prepare_animal_params(animal_params)]
end
def prepare_animal_params animal_params
# here we manipulate the model parameters however we want
# e.g. animal_params[:age] = 1 if animal_params[:age] < 0
...
# importantly this method must return the model params
animal_params
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment