class WeatherController
WeatherController
Single-resource controller that powers the weather search page.
Routes
GET / → index (root) GET /weather/search → search → redirects to root with address param
Flow
-
User lands on the root page (empty search).
-
Submitting the search form hits
search, which redirects back to root with the +address+ query parameter. -
indexdetects the address, calls {Services::Application::WeatherByAddress} to geocode and fetch weather, and assigns +@result+ for the view. -
On error, +@error+ is set and shown in the +_error+ partial.
Public Instance Methods
Source
# File app/controllers/weather_controller.rb 29 def index 30 @address = params[:address].to_s.strip 31 return unless @address.present? 32 33 @result = Services::Application::WeatherByAddress.new.call(@address) 34 rescue StandardError => e 35 @error = e.message 36 end
Renders the main weather page.
When +params+ is present, delegates to {Services::Application::WeatherByAddress} and assigns:
-
+@result+ — a {Services::Application::WeatherByAddress::Result} with location, current weather, hourly and daily forecasts.
-
+@error+ — error message string if the service raises.
-
+@address+ — the raw search string (always set).
Source
# File app/controllers/weather_controller.rb 40 def search 41 redirect_to root_path(address: params[:address]) 42 end
Accepts the search form submission and redirects to +root_path+ with the address as a query parameter, keeping the URL bookmarkable.