Created
July 30, 2013 11:54
-
-
Save ankit8898/6112306 to your computer and use it in GitHub Desktop.
Strong parametes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
helper_method :permitted_params | |
private | |
def permitted_params | |
PermittedParams.new(params) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++++++++++++raw+++++{"utf8"=>"✓", "authenticity_token"=>"CfGubZxXPW/7XEHEhnFTjKVKByNxGb5r3KJqoqoXHms=", "unit_plate"=>{"name"=>"Okyqaa", "name_type"=>"boyqaa", "parent_id"=>"", "unit_plate_components_attributes"=>{"1375184158151"=>{"component_id"=>"115", "_destroy"=>"false"}}}, "commit"=>"Create Unit plate", "action"=>"create", "controller"=>"admin/unit_plates"} | |
Unpermitted parameters: component_id, _destroy | |
Unpermitted parameters: name_type | |
++++++++++++++++++++{"name"=>"Okyqaa", "parent_id"=>"", "unit_plate_components_attributes"=>{"1375184158151"=>{}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Klass = Struct.new(:params) unless defined?(Klass | |
class PermittedParams < Klass | |
#For: admin/unit_plates/new | |
def unit_plate | |
params.require(:unit_plate).permit(:name,:name_type,:type,:unit_plate_components_attributes => [:id, '_destroy',:component_id,:name,:type,:parent_id,:lft,:rgt,:depth]) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
Rails.logger.info "+++++++++++++++raw+++++#{params.inspect}" | |
Rails.logger.info "++++++++++++++++++++#{permitted_params.unit_plate.inspect}" | |
@unit_plate = UnitPlate.new(permitted_params.unit_plate) | |
if @unit_plate.save | |
redirect_to edit_admin_unit_plate_url(@unit_plate), :notice => 'Template was successfully created.' | |
else | |
render :action => 'new' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment