Skip to content

Commit

Permalink
added styles to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitchauhan2065 committed Apr 6, 2018
1 parent aa8602f commit 062a291
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
6 changes: 3 additions & 3 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create
#render plain: params[:article].inspect
@article = Article.new(article_params)
if @article.save
flash[:notice] = "Article was successfully created"
flash[:success] = "Article was successfully created"
redirect_to article_path(@article)
else
render 'new'
Expand All @@ -31,7 +31,7 @@ def update


if @article.update(article_params)
flash[:notice] = "article was successfully updated"
flash[:success] = "article was successfully updated"
redirect_to article_path(@article)
else
render 'edit'
Expand All @@ -45,7 +45,7 @@ def show
def destroy

@article.destroy
flash[:notice] = "Article was successfully deleted"
flash[:danger] = "Article was successfully deleted"
redirect_to articles_path
end
private
Expand Down
14 changes: 2 additions & 12 deletions app/views/articles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
<% if @article.errors.any? %>
<h2>
The following errors prevented the article from getting created
</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>

<%= render "shared/errors", obj: @article %>

<div class="row">
<div class="col-xs-12">
Expand All @@ -35,7 +25,7 @@
<div class="col-sm-10 col-sm-offset-2">
<%= f.submit class: "btn btn-primary btn-lg" %>
</div>
</div>
</div>
<% end %>

<div class="col-xs-4 col-xs-offset-4">
Expand Down
15 changes: 10 additions & 5 deletions app/views/layouts/_messages.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<% flash.each do |name, msg| %>
<ul>
<li><%= msg %></li>
</ul>
<% end %>
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<% flash.each do |name, msg| %>
<div class= 'alert alert-<%="#{name}" %>'>
<a href="#" class="close" data-dismiss= "alert">&#215;</a>
<%= content_tag :div , msg, :id => "flash_#{name}" if msg.is_a?(String) %>
</div>
<% end %>
</div>
</div>
23 changes: 23 additions & 0 deletions app/views/shared/_errors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% if obj.errors.any? %>
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="panel panel-danger">
<div class="panel-heading">
<h2 class="panel-title">
<%= pluralize(obj.errors.count, "error") %>
prohibited this article from being saved:
</h2>
<div class="panel-body">

<ul>
<% obj.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>

</div>
</div>
</div>
</div>
</div>
<% end %>

0 comments on commit 062a291

Please sign in to comment.