
Table of contents
Codeblocks#
Code language:
Ruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Gemfile
gem 'httparty'
# app/services/weather_api.rb
require 'httparty'
class WeatherApi
API_KEY = 'your_api_key'
BASE_URL = 'https://api.openweathermap.org/data/2.5/weather'
def fetch_weather(city)
url = "#{BASE_URL}?q=#{city}&appid=#{API_KEY}&units=metric"
response = HTTParty.get(url)
raise "API Error: #{response.code}" unless response.success?
response.parsed_body
end
end
# app/controllers/weather_controller.rb
def show
city = params[:city]
weather_data = WeatherApi.new.fetch_weather(city)
@temperature = weather_data['main']['temp']
end
Alerts#
Default#
This is default alert.
With icon, heading, and dismiss#
Information
This is just for your information.
Heads Up!
Your profile has been updated successfully.
Error :(
Failed to save your changes. Please try again.
Attention
This action requires confirmation.
With icon, outline, and dismiss#
An example outlined accent alert with an icon.
An example outlined success alert with an icon.
An example outlined danger alert with an icon.
An example outlined attention alert with an icon.
With links#
Information
This is an important notification that requires your attention.
You can update your settings here.
An example showing the warning
type prompt.
Markdown support#
Markdown enabled alert#
This content is processed as Markdown.