kohactive / assetable

Dead simple asset uploader attachments for your active record models
MIT License
5 stars 10 forks source link

strong params #13

Open rlmattax opened 10 years ago

rlmattax commented 10 years ago

Do you guys have any suggestions on how to make the strong params suck less?

On the activity model: galleryable :briefing_gallery, :debriefing_gallery

In the activities controller: params.require(:activity).permit([:name, :description, :start_at, :end_at, :briefing_gallery_attributes=>{:asset_attachments_attributes=>[:id,:asset_id,:sort_order]}, :debriefing_gallery_attributes=>{:asset_attachments_attributes=>[:id,:asset_id,:sort_order]}])

johnkoht commented 10 years ago

I've been thinking about this a bit. I think we need to abstract the strong params into a class, e.g. Assetabler::Gallery::permitted_params so you could call:

params.require(:activity).permit([
  :name,
  :description, 
  :start_at,
  :end_at,
  briefing_gallery_attributes: Assetabler::Gallery::permitted_params,
  debriefing_gallery_attributes: Assetabler::Gallery::permitted_params
])

We could add another for an asset: Assetabler::Asset::permitted_params

This is similar to how spree handles it -- https://github.com/spree/spree/blob/master/core/lib/spree/core/controller_helpers/strong_parameters.rb

rlmattax commented 10 years ago

I was thinking very similarly. I might try it in my own branch.