To send an array of values, append an empty pair of square brackets "" to the key name: The params hash is not limited to one-dimensional keys and values. # would have been to render the "create" view. If This line overrides the default rendering behavior, which # this RESTful request will be "/clients", and the data will be # from an HTML form which the user has submitted. # this action would look like this in order to list activated # to the way in which the parameters are accessed.
![action strings bug action strings bug](https://blog.nightly.mozilla.org/files/2021/05/headlines93_0-768x274.png)
# by an HTTP GET request, but this does not make any difference # This action uses query string parameters because it gets run render "new" end end end class ClientsController < ApplicationController save redirect_to else # This line overrides the default rendering behavior, which # would have been to render the "create" view. The URL for # this RESTful request will be "/clients", and the data will be # sent as part of the request body. They are most likely coming # from an HTML form which the user has submitted. inactivated end end # This action uses POST parameters. The URL for # this action would look like this in order to list activated # clients: /clients?status=activated def index if params = "activated" = Client.
![action strings bug action strings bug](https://m.media-amazon.com/images/I/715jBuG4MwL._AC_SL1500_.jpg)
Rails does not make any distinction between query string parameters and POST parameters, and both are available in the params hash in your controller:Ĭlass ClientsController < ApplicationController # This action uses query string parameters because it gets run # by an HTTP GET request, but this does not make any difference # to the way in which the parameters are accessed. It's called POST data because it can only be sent as part of an HTTP POST request. This information usually comes from an HTML form which has been filled in by the user. The second type of parameter is usually referred to as POST data. The query string is everything after "?" in the URL. The first are parameters that are sent as part of the URL, called query string parameters. There are two kinds of parameters possible in a web application. You will probably want to access data sent in by the user or other parameters in your controller actions. It is a best practice to lower the visibility of methods (with private or protected) which are not intended to be actions, like auxiliary methods or filters. Only public methods are callable as actions. This guide will cover some of these, but if you're curious to see what's in there, you can see all of them in the API documentation or in the source itself.
![action strings bug action strings bug](https://us.v-cdn.net/6030815/uploads/ZUCTKVFJTS3B/clipboard01.png)
The Layouts and Rendering Guide explains this in more detail.ĪpplicationController inherits from ActionController::Base, which defines a number of helpful methods.