![]() The one we got is called strong parameters, which requires us to tell Rails exactly which parameters are allowed into our controller actions. Sometime we get "ActiveModel::ForbiddenAttributesError" error. So for example, if we're sending this JSON content: If the "Content-Type" header of our request is set to "application/json", Rails will automatically convert our parameters into the params hash, which we can access as we would normally. If we're writing a web service application, we might be more comfortable accepting parameters in JSON format. # would have been to render the "create" view. ![]() If This line overrides the default rendering behavior, which # this RESTful request will be "/users", 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. # by an HTTP GET request, but this does not make any difference # This action uses query string parameters because it gets run Rails does not make any distinction between query string parameters and POST parameters, and both are available in the params hash in our controller:Ĭlass UsersController < ApplicationController 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: Most likely, we want to access data sent in by the user or other parameters in our controller actions.
0 Comments
Leave a Reply. |