2

Below is my index action:

def index
  @api = Api.find_by(name: params[:name])
  @descriptions = @api.descriptions.all

  if valid_json?(@descriptions.first.value)
  render json: JSON.pretty_generate(JSON.parse(@descriptions.first.value))  
else
  flash[:danger] = "Something wrong with your JSON data."
  redirect_to root_path
end  

end

when I use url "http://localhost:3000/xxxxxxxx?name=1234567890" It will return data in JSON format.

However, if I change params[:name] to params[:action] and url to "http://localhost:3000/xxxxxxxx?action=1234567890", then it will not work anymore.

I know it is because params[:action] is equal index in this case, but is there any way I can still pass params[:action]=12345 or whatever I use in url?

Dreams
  • 8,288
  • 10
  • 45
  • 71
  • In params rails passes 'action' and 'controller' parameter which clash with ur parameter. try different name than 'action'. – Sachin R Jun 09 '15 at 06:14

1 Answers1

2

Have a look at this question.

action, controller are prohibited words. You should not use it in your params.

Community
  • 1
  • 1
BinaryMee
  • 2,102
  • 5
  • 27
  • 46