diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2b5c010..045b7e0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,4 +21,8 @@ module ApplicationHelper } }.to_json.html_safe if weather_art.image.attached? end + + def admin? + current_user&.admin? + end end diff --git a/app/views/cities/_admin_panel.html.erb b/app/views/cities/_admin_panel.html.erb new file mode 100644 index 0000000..bcc918c --- /dev/null +++ b/app/views/cities/_admin_panel.html.erb @@ -0,0 +1,45 @@ +<% if admin? %> +
+
+ + + +

Admin Panel

+
+ +
+ +
+

Statistics

+
+
+
Total Images
+
<%= @weather_art.city.weather_arts.count %>
+
+ +
+
Today's Images
+
<%= @weather_art.city.weather_arts.where("created_at >= ?", Time.zone.now.beginning_of_day).count %>
+
+
+
+ + +
+

Actions

+
+ <%= button_to "Generate New Art", "#", + method: :post, + data: { + controller: "generate-art", + action: "generate-art#generate", + city_id: @weather_art.city.id + }, + class: "btn btn-primary" %> + + <%= link_to "Edit City", edit_city_path(@weather_art.city), class: "btn btn-secondary" %> +
+
+
+
+<% end %> \ No newline at end of file diff --git a/app/views/weather_arts/show.html.erb b/app/views/weather_arts/show.html.erb index 78990ad..b3261df 100644 --- a/app/views/weather_arts/show.html.erb +++ b/app/views/weather_arts/show.html.erb @@ -7,7 +7,6 @@
-
<%= link_to city_path(@weather_art.city), diff --git a/config/database.yml b/config/database.yml index 5dd2ac0..8031255 100644 --- a/config/database.yml +++ b/config/database.yml @@ -12,7 +12,7 @@ default: &default development: <<: *default # database: storage/development.sqlite3 - url: <%= Rails.application.credentials.db_dev.url %> + url: <%= Rails.application.credentials.dig(:db_dev, :url) %> # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake".