Reputation: 3
I am trying to display a flash error message on invalid email/password input:
Snippet of the layout:
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
Controller:
class SessionsController < ApplicationController
def create
user = User.find_by(email: params[:sessions][:email].downcase)
if user && user.authenticate(params[:sessions][:password])
# Sign the user in and redirect to the user's show page.
else
flash.now[:error] = "Invalid email/password combination"
render 'new'
end
end
end
But I get the above flash message as plain black text, when it should be red with stylized background.
Only :success
displays the value(flash message) in green plain text, rest of the keys show plain text.
What am I doing wrong? How do I fix this?
Upvotes: 0
Views: 1867
Reputation: 371
If you're using bootstrap, try using flash.now[:danger]
instead of flash.now[:error]
Upvotes: 3