Browse Source

Improve all the devise stuff

Chris Oliver 7 years ago
parent
commit
419a84f946

+ 8 - 0
app/assets/stylesheets/application.scss

@@ -8,3 +8,11 @@
 body > .container {
   margin-top: 40px;
 }
+
+// Fixes bootstrap nav-brand container overlap
+@include media-breakpoint-down(xs) {
+  .container {
+    margin-left: 0;
+    margin-right: 0;
+  }
+}

+ 20 - 0
app/helpers/application_helper.rb

@@ -0,0 +1,20 @@
+module ApplicationHelper
+  def bootstrap_class_for(flash_type)
+    {
+      success: "alert-success",
+      error: "alert-danger",
+      alert: "alert-warning",
+      notice: "alert-info"
+    }.stringify_keys[flash_type.to_s] || flash_type.to_s
+  end
+
+  def flash_messages(opts={})
+    flash.each do |msg_type, message|
+      concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)}") do
+        concat content_tag(:button, content_tag(:span, "×"), class: "close", data: { dismiss: 'alert' })
+        concat message
+      end)
+    end
+    nil
+  end
+end

+ 14 - 0
app/helpers/devise_helper.rb

@@ -0,0 +1,14 @@
+module DeviseHelper
+  def devise_error_messages!
+    return '' if resource.errors.empty?
+
+    messages = resource.errors.full_messages.map { |msg| content_tag(:div, msg) }.join
+    html = <<-HTML
+    <div class="alert alert-danger">
+      #{messages}
+    </div>
+    HTML
+
+    html.html_safe
+  end
+end

+ 1 - 6
app/views/shared/_notices.html.erb

@@ -1,6 +1 @@
-<% if notice %>
-  <p class="notice"><%= notice %></p>
-<% end %>
-<% if alert %>
-  <p class="alert"><%= alert %></p>
-<% end %>
+<%= flash_messages %>

+ 1 - 1
template.rb

@@ -4,7 +4,7 @@ end
 
 def add_gems
   gem 'devise', github: 'plataformatec/devise' #, '~> 4.2.1'
-  gem 'devise-bootstrapped', github: 'king601/devise-bootstrapped', branch: 'bootstrap4'
+  gem 'devise-bootstrapped', github: 'excid3/devise-bootstrapped', branch: 'bootstrap4'
   gem 'jquery-rails', '~> 4.3.1'
   gem 'bootstrap', '~> 4.0.0.alpha6'
   gem 'rails-assets-tether', '>= 1.3.3', source: 'https://rails-assets.org'