Skip to content

Instantly share code, notes, and snippets.

@westonplatter
Created October 24, 2013 04:33
Show Gist options
  • Select an option

  • Save westonplatter/7131411 to your computer and use it in GitHub Desktop.

Select an option

Save westonplatter/7131411 to your computer and use it in GitHub Desktop.
module Spree
class OrdersController < Spree::StoreController
# this gets included by the Spree::BaseController which the Spree::StoreController inherits from
include Spree::Core::ControllerHelpers::StrongParameters
# ... a bunch of controller methods ...
private
def order_params
if params[:order]
params[:order].permit(*permitted_order_attributes) # <<<=== dynamically reference defined strong parameters
else
{}
end
end
end
# https://github.com/spree/spree/blob/master/core/lib/spree/permitted_attributes.rb
module Spree
module PermittedAttributes
ATTRIBUTES = [:line_item_attributes]
mattr_reader *ATTRIBUTES
@@line_item_attributes = [:id, :variant_id, :quantity]
end
end
# https://github.com/spree/spree/blob/master/core/lib/spree/core/controller_helpers/strong_parameters.rb
module Spree
module Core
module ControllerHelpers
module StrongParameters
def permitted_attributes
Spree::PermittedAttributes
end
delegate *Spree::PermittedAttributes::ATTRIBUTES,
:to => :permitted_attributes,
:prefix => :permitted
def permitted_order_attributes
permitted_checkout_attributes + [
:line_items_attributes => permitted_line_item_attributes
]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment