Skip to content

Commit

Permalink
Updated with better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jadevance committed Jul 21, 2016
1 parent a915d52 commit 3a607fa
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def new
end

def create
@book = Book.create(book_params[:book])
@book = Book.new(book_params[:book])
if @book.save
flash[:success] = 'New book added!'
redirect_to books_path
Expand All @@ -29,10 +29,8 @@ def edit
def update
@book = Book.update(params[:id], book_params[:book])
if @book.save
flash[:success] = 'Book information updated!'
redirect_to books_path
else
flash.now[:error] = 'Entries must have a title.'
render :new
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/views/books/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<% if @book.errors.any? %>
<ul>
<% @book.errors.each do |column, message| %>
<li>
<%= column.capitalize %> <%= message %>
</li>
<% end %>
</ul>
<% end %>

<h1>
Add a book
</h1>
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
196 changes: 196 additions & 0 deletions log/development.log
Original file line number Diff line number Diff line change
Expand Up @@ -4825,3 +4825,199 @@ Migrating to AddNullFalseToTitles (20160721070517)
 (0.1ms) begin transaction
 (0.0ms) commit transaction
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Started GET "/books" for ::1 at 2016-07-21 00:09:03 -0700
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.2ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (7.3ms)
Completed 200 OK in 29ms (Views: 25.7ms | ActiveRecord: 0.5ms)


Started GET "/books/new" for ::1 at 2016-07-21 00:09:05 -0700
Processing by BooksController#new as HTML
Rendering books/new.html.erb within layouts/application
Rendered books/_entryform.html.erb (2.1ms)
Rendered books/new.html.erb within layouts/application (3.8ms)
Completed 200 OK in 27ms (Views: 24.3ms | ActiveRecord: 0.0ms)


Started POST "/books" for ::1 at 2016-07-21 00:09:07 -0700
Processing by BooksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ldXtbxAtjA/ZT9+8RJpGLzeZYyApYzGSCf7And2UuGCMZdpSyLeUop3nEumYB0EJiPd4/FCpb+aGlmTcWCiszw==", "book"=>{"title"=>"", "author"=>"", "description"=>""}, "commit"=>"Submit"}
Unpermitted parameters: utf8, authenticity_token, commit
 (0.1ms) begin transaction
SQL (0.3ms) INSERT INTO "books" ("created_at", "updated_at", "title", "author", "description") VALUES (?, ?, ?, ?, ?) [["created_at", 2016-07-21 07:09:07 UTC], ["updated_at", 2016-07-21 07:09:07 UTC], ["title", ""], ["author", ""], ["description", ""]]
 (1.1ms) commit transaction
 (0.0ms) begin transaction
 (0.0ms) commit transaction
Redirected to http://localhost:3000/books
Completed 302 Found in 5ms (ActiveRecord: 1.6ms)


Started GET "/books" for ::1 at 2016-07-21 00:09:07 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.3ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (2.3ms)
Completed 200 OK in 24ms (Views: 21.5ms | ActiveRecord: 0.3ms)


Started GET "/books/new" for ::1 at 2016-07-21 00:10:26 -0700
Processing by BooksController#new as HTML
Rendering books/new.html.erb within layouts/application
Rendered books/_entryform.html.erb (2.2ms)
Rendered books/new.html.erb within layouts/application (4.3ms)
Completed 200 OK in 28ms (Views: 25.6ms | ActiveRecord: 0.0ms)


Started POST "/books" for ::1 at 2016-07-21 00:10:27 -0700
Processing by BooksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xjwcqYv4tvjtJkqU4T1AMVFHD1NinGMxx/f63ZWlDjffjCuUU2KuVamOh8E9oEcX7ikUjxtWPUVIn16cEBkamA==", "book"=>{"title"=>"", "author"=>"", "description"=>""}, "commit"=>"Submit"}
Unpermitted parameters: utf8, authenticity_token, commit
 (0.2ms) begin transaction
SQL (0.3ms) INSERT INTO "books" ("created_at", "updated_at", "title", "author", "description") VALUES (?, ?, ?, ?, ?) [["created_at", 2016-07-21 07:10:27 UTC], ["updated_at", 2016-07-21 07:10:27 UTC], ["title", ""], ["author", ""], ["description", ""]]
 (1.2ms) commit transaction
 (0.0ms) begin transaction
 (0.0ms) commit transaction
Redirected to http://localhost:3000/books
Completed 302 Found in 4ms (ActiveRecord: 1.8ms)


Started GET "/books" for ::1 at 2016-07-21 00:10:27 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.5ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (3.8ms)
Completed 200 OK in 30ms (Views: 27.3ms | ActiveRecord: 0.5ms)


Started GET "/books/new" for ::1 at 2016-07-21 00:10:30 -0700
Processing by BooksController#new as HTML
Rendering books/new.html.erb within layouts/application
Rendered books/_entryform.html.erb (2.1ms)
Rendered books/new.html.erb within layouts/application (3.7ms)
Completed 200 OK in 28ms (Views: 26.2ms | ActiveRecord: 0.0ms)


Started POST "/books" for ::1 at 2016-07-21 00:11:11 -0700
Processing by BooksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zHvchuKPupMULuc1yQpMBBNYFxLrgWfSysvpTYGHxojVy+u7OhWiPlCGKmAVl0sirDYMzpJLOaZFo00MBDvSJw==", "book"=>{"title"=>"", "author"=>"", "description"=>""}, "commit"=>"Submit"}
Unpermitted parameters: utf8, authenticity_token, commit
 (0.1ms) begin transaction
SQL (0.6ms) INSERT INTO "books" ("created_at", "updated_at", "title", "author", "description") VALUES (?, ?, ?, ?, ?) [["created_at", 2016-07-21 07:11:11 UTC], ["updated_at", 2016-07-21 07:11:11 UTC], ["title", ""], ["author", ""], ["description", ""]]
 (1.1ms) commit transaction
 (0.0ms) begin transaction
 (0.1ms) commit transaction
Redirected to http://localhost:3000/books
Completed 302 Found in 6ms (ActiveRecord: 1.8ms)


Started GET "/books" for ::1 at 2016-07-21 00:11:11 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.3ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (2.4ms)
Completed 200 OK in 21ms (Views: 19.7ms | ActiveRecord: 0.2ms)


Started GET "/books/11" for ::1 at 2016-07-21 00:11:18 -0700
Processing by BooksController#show as HTML
Parameters: {"id"=>"11"}
Book Load (0.2ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT ? [["id", 11], ["LIMIT", 1]]
Rendering books/show.html.erb within layouts/application
Rendered books/show.html.erb within layouts/application (0.8ms)
Completed 200 OK in 22ms (Views: 19.0ms | ActiveRecord: 0.2ms)


Started DELETE "/books/11" for ::1 at 2016-07-21 00:11:19 -0700
Processing by BooksController#destroy as HTML
Parameters: {"authenticity_token"=>"n5YEErsJY7xhiUX2IzVXQ2Kn8QxiiqJcxNe4FOYs0AAj9cIWOK+yuf+D8sv9bkuZebU0kW/MWrlKL8YtCcDOlA==", "id"=>"11"}
Book Load (0.1ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT ? [["id", 11], ["LIMIT", 1]]
 (0.0ms) begin transaction
SQL (0.2ms) DELETE FROM "books" WHERE "books"."id" = ? [["id", 11]]
 (1.2ms) commit transaction
Redirected to http://localhost:3000/books
Completed 302 Found in 3ms (ActiveRecord: 1.5ms)


Started GET "/books" for ::1 at 2016-07-21 00:11:19 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.2ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (2.7ms)
Completed 200 OK in 24ms (Views: 22.3ms | ActiveRecord: 0.2ms)


Started GET "/books/new" for ::1 at 2016-07-21 00:12:55 -0700
Processing by BooksController#new as HTML
Rendering books/new.html.erb within layouts/application
Rendered books/_entryform.html.erb (2.2ms)
Rendered books/new.html.erb within layouts/application (4.0ms)
Completed 200 OK in 32ms (Views: 24.3ms | ActiveRecord: 0.6ms)


Started POST "/books" for ::1 at 2016-07-21 00:12:56 -0700
Processing by BooksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"TMMz+V2hpHlu4vi/nR/5mep57dOmlpR/s4OQjo3ic5BVcwTEhTu81CpKNepBgv6/VRf2D99cygs86zTPCF5nPw==", "book"=>{"title"=>"", "author"=>"", "description"=>""}, "commit"=>"Submit"}
Unpermitted parameters: utf8, authenticity_token, commit
 (0.1ms) begin transaction
SQL (0.3ms) INSERT INTO "books" ("created_at", "updated_at", "title", "author", "description") VALUES (?, ?, ?, ?, ?) [["created_at", 2016-07-21 07:12:56 UTC], ["updated_at", 2016-07-21 07:12:56 UTC], ["title", ""], ["author", ""], ["description", ""]]
 (1.1ms) commit transaction
Redirected to http://localhost:3000/books
Completed 302 Found in 4ms (ActiveRecord: 1.5ms)


Started GET "/books" for ::1 at 2016-07-21 00:12:56 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.2ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (2.2ms)
Completed 200 OK in 22ms (Views: 20.7ms | ActiveRecord: 0.2ms)


Started PUT "/books/12/rank" for ::1 at 2016-07-21 00:13:00 -0700
Processing by BooksController#rank as HTML
Parameters: {"authenticity_token"=>"N8S+Vxl6sRcYzzjPhL5rZUPox1dWq+OpsnhmViABo1qLp3hTmtxgEobFj/Ja5Xe/WPoCylvtG0w8gBhvz+29zg==", "id"=>"12"}
Book Load (0.1ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT ? [["id", 12], ["LIMIT", 1]]
 (0.0ms) begin transaction
SQL (0.2ms) UPDATE "books" SET "rank" = ?, "updated_at" = ? WHERE "books"."id" = ? [["rank", 1], ["updated_at", 2016-07-21 07:13:00 UTC], ["id", 12]]
 (1.2ms) commit transaction
Redirected to http://localhost:3000/books
Completed 302 Found in 4ms (ActiveRecord: 1.6ms)


Started GET "/books" for ::1 at 2016-07-21 00:13:00 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.2ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (2.5ms)
Completed 200 OK in 20ms (Views: 18.7ms | ActiveRecord: 0.2ms)


Started GET "/books/1" for ::1 at 2016-07-21 00:13:05 -0700
Processing by BooksController#show as HTML
Parameters: {"id"=>"1"}
Book Load (0.1ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
Rendering books/show.html.erb within layouts/application
Rendered books/show.html.erb within layouts/application (1.2ms)
Completed 200 OK in 23ms (Views: 20.2ms | ActiveRecord: 0.1ms)


Started GET "/books/5" for ::1 at 2016-07-21 00:13:09 -0700
Processing by BooksController#show as HTML
Parameters: {"id"=>"5"}
Book Load (0.1ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]]
Rendering books/show.html.erb within layouts/application
Rendered books/show.html.erb within layouts/application (1.0ms)
Completed 200 OK in 21ms (Views: 19.2ms | ActiveRecord: 0.1ms)


Started GET "/books" for ::1 at 2016-07-21 00:13:13 -0700
Processing by BooksController#index as HTML
Rendering books/index.html.erb within layouts/application
Book Load (0.2ms) SELECT "books".* FROM "books" ORDER BY "books"."rank" DESC
Rendered books/index.html.erb within layouts/application (11.2ms)
Completed 200 OK in 35ms (Views: 32.9ms | ActiveRecord: 0.2ms)


0 comments on commit 3a607fa

Please sign in to comment.