Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Add Flash Notices for Failure
Browse files Browse the repository at this point in the history
When a Task #create or #update operation fails, a flash notice is
presented to the user when the task index page reloads. You can see this
easily by trying to create a new task with the same name as an existing
task.

Additionally, cleaned up controllers to not have unneeded format
blocks.
  • Loading branch information
awood45 committed Jun 19, 2014
1 parent 4cb4825 commit ed2395f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
20 changes: 12 additions & 8 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ def index
end

def create
respond_to do |format|
@task = Task.new(task_create_params)
@task.save
format.html { redirect_to tasks_path }
@task = Task.new(task_create_params)
if @task.save
redirect_to tasks_path
else
flash[:error] = "Task creation failed!"
redirect_to tasks_path
end
end

def update
respond_to do |format|
@task = Task.find(params[:id])
@task.update(task_update_params)
format.html { redirect_to tasks_path }
@task = Task.find(params[:id])
if @task.update(task_update_params)
redirect_to tasks_path
else
flash[:error] = "Task failed to update!"
redirect_to tasks_path
end
end

Expand Down
8 changes: 8 additions & 0 deletions app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<div id="task-index">
<% if msg = flash[:error] %>
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
&times;
</button>
<strong><%= msg %></strong>
</div>
<% end %>
<ul class="list-group" id="tasks">
<% @tasks.each do |task| %>
<% if task.completed_flag %>
Expand Down

0 comments on commit ed2395f

Please sign in to comment.