Parameters
suggest changeControllers read HTTP parameters (the ?name=foo query string, and the same params hash for other formats) and choose a response from them. Rails does not give you separate GET and POST hashes. Query, body, and route params are merged into params.
class UsersController < ApplicationController
def index
respond_to do |format|
format.html do
if params[:name] == "john"
render html: "Hello John".html_safe
else
render html: "Hello someone".html_safe
end
end
end
end
end
As usual our route:
resources :users, only: [:index]
Access the URL /users?name=john and the output will be Hello John, access /users?name=whatever and the output will be Hello someone
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents