Home > Back-end >  How can i know what parameter i am sending?
How can i know what parameter i am sending?

Time:12-16

i implemented a function to permit the parameters

def send_params
        params.require(:article).permit(:color, :skin, :cover)
      end

right now i want to know what parameter i am sending

for example only i am sending the color in this case:

#<ActionController::Parameters {"color"=>""} permitted: true>

with this conditional, is validating the value of color, does not matter the value, i am interesting the parameter that i am sending

 if params_search[:color].present?

CodePudding user response:

You can use gem pry

def create 
  binding.pry
  # some logic using `send_params`
end
  • The steps:
  1. add binding.pry to action of controller
  2. go to Postman and send data
  3. go to console where running rails s
  4. call params or send_params

CodePudding user response:

In the logs you can see what params you are sending. For example if you post to /articles and you send all three params you would see it like this:

Started POST "/articles" for [IP_ADDRESS] at [DATE_TIME_STAMP]
Processing by ArticlesController#create as [html/json/something_else]
Parameters: {"article"=>"{"color"=>"blue", "skin"=>"skin value", "cover"=>"some cover"}}

If you only send the color than the logs would look like this:

Started POST "/articles" for [IP_ADDRESS] at [DATE_TIME_STAMP]
Processing by ArticlesController#create as [html/json/something_else]
Parameters: {"article"=>"{"color"=>"blue"}}

You can access the params object with: params[:article] and if you want to access the color: params[:article][:color]

  • Related