rawnet / rawnet-admin

An inheritable admin interface for Ruby on Rails apps
MIT License
0 stars 2 forks source link

Document strong parameters usage #5

Open tombeynon opened 9 years ago

tombeynon commented 9 years ago

RawnetAdmin expects a #{resource}_params method like the following..

def user_params
    params.require(:user).permit(:name, :email)
end

Since the above will throw an error on the new action (as no params are submitted, require(:user) throws a hissy), the permitted_params method will catch the error on new and return an empty hash on new only.

You can override permitted_params instead if you like, just make sure you don't call require in here and use a nested hash instead.

def permitted_params
    params.permit(user: [:name, :email])
end

Ultimately, resource_params is the top-level method to obtain the params for the resource. This returns the hash of parameters without the resource key.

This needs documenting ASAP, although it's the same behaviour as InheritedResources