I find it more convenient to check response for some requests from within console
>> app.put '/users/2/' => 500
But wasn't able to find a way to specify request parameters. How I have to do that?
Specifically, params refers to the parameters being passed to the controller via a GET or POST request. In a GET request, params get passed to the controller from the URL in the user's browser.
While params appears to be a hash, it is actually an instance of the ActionController::Parameters class.
params[:id] is meant to be the string that uniquely identifies a (RESTful) resource within your Rails application. It is found in the URL after the resource's name.
Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .
If you want to put or post to a URL there are also methods for that. You can copy/paste the parameters exactly as they are displayed in your Rails production log:
app.post('/foo', {"this" => "that", "items" => ["bar", "baz"]}) app.put('/foo', {"this" => "that", "items" => ["bar", "baz"]})
If you want to sent a custom header, you can add an optional third parameter:
app.post('/foo', {:this => "that", :items => ["bar", "baz"]}, {"X-Do-Something" => "yes"})
Any of the get/post/put/delete methods will display their full log output on the console for you to examine. If you want to get information such as the response body returned, HTTP status or response headers these are easy too:
app.response.body app.response.status app.response.headers.inspect
Source: http://andyjeffries.co.uk/articles/debug-level-logging-for-a-single-rails-production-request
The above has changed to
app.post '/foo', params: {"this" => "that", "items" => ["bar", "baz"]}
Also for forms I had to give an authenticity_token as well. So in my example the full command was
app.post '/login', params: {email: '[email protected]', password: 'abcd', authenticity_token: 'my_authenticity_token_generated_for_this_view' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With