Skip to content

Instantly share code, notes, and snippets.

@mdunbavan
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save mdunbavan/1515885b419faaba596d to your computer and use it in GitHub Desktop.

Select an option

Save mdunbavan/1515885b419faaba596d to your computer and use it in GitHub Desktop.
Rails image uploading models and controllers
#controllers for the gallery and image
#images_controller.rb that creates the image
class ImagesController < ApplicationController
before_action :set_image, only: [:show, :edit, :update, :destroy]
def show
@image = Image.find(params[:id])
end
def index
@images = Image.all
end
def new
@image = Image.new
end
def create
@image = Image.new(image_params)
respond_to do |format|
if @image.save
format.html { redirect_to @image, notice: 'Book was successfully created.' }
format.json { render action: 'show', status: :created, location: @image }
else
format.html { render action: 'new' }
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end
def edit
end
def destroy
@image.destroy
respond_to do |format|
format.html { redirect_to images_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_image
@image = Image.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def image_params
params.require(:image).permit(:file)
end
end
# galleries_controller.rb that creates the gallery and builds it
class GalleriesController < ApplicationController
before_action :set_gallery, only: [:show, :edit, :update, :destroy]
def index
@galleries = Gallery.all
end
def show
@gallery = Gallery.find(params[:id])
@images = @gallery.images
end
def new
@gallery = Gallery.new
@image = @gallery.build_book
@gallery.images.build
end
def edit
end
def create
@gallery = Gallery.new(gallery_params)
@gallery.images.build
respond_to do |format|
if @gallery.save
format.html { redirect_to @gallery, notice: 'Gallery was successfully created.' }
format.json { render action: 'show', status: :created, location: @gallery }
else
format.html { render action: 'new' }
format.json { render json: @gallery.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @gallery.update(gallery_params)
format.html { redirect_to @gallery, notice: 'Gallery was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @gallery.errors, status: :unprocessable_entity }
end
end
end
def destroy
@gallery.destroy
respond_to do |format|
format.html { redirect_to galleries_url }
format.json { head :no_content }
end
end
private
def set_gallery
@gallery = Gallery.find(params[:id])
end
def gallery_params
params.require(:gallery).permit(:name, :book_id, :image)
end
end
# Here I will show the forms that are being used, they are nested within each other for the main book page
# book/_form.html.erb
<%= simple_form_for(@book, :html => { :multipart => true }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.file_field :jacket_cover %>
<%= f.input :title %>
<%= f.input :synopsis, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
<%= f.input :body, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
<%= f.input :age %>
<%= f.input :publisher %>
</div>
<%= f.simple_fields_for :author do |a| %>
<%= a.input :name %>
<%= a.input :biography, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
<% end %>
<%= f.simple_fields_for :gallery do |builder| %>
<%= render 'galleries/form', :f => builder %>
<% end %>
<div class="actions">
<%= f.button :submit %>
</div>
<% end %>
# The galleries form then has image fields nested inside that
# galleries/_form.html.erb
<div class="inputs">
<%= f.input :name %>
<%= f.input :book_id %>
<%#= f.simple_fields_for :image do |a| %>
<%#= a.input_field :file, as: :file, multiple: true, name: 'gallery[image]' %>
<%# end %>
<%= f.simple_fields_for :image do |builder| %>
<%= render 'images/form', :f => builder %>
<% end %>
</div>
# The images form is very simple with multiple uploadable images
# images/_form.html.erb
<div class="inputs">
<%#= f.input :file %>
<%= f.input_field :file, as: :file, multiple: true, name: 'gallery[image]' %>
</div>
# as you can see here the forms are nested. When I create the book it works and when I check /galleries the gallery is
# added and the relationship to the book is created so thats fine. The issue is that the images are not being added to the
# gallery itself. Here is my db:schema below
ActiveRecord::Schema.define(version: 20140916190401) do
create_table "authors", force: true do |t|
t.string "name"
t.text "biography"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "books", force: true do |t|
t.string "title"
t.text "synopsis"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
t.string "jacket_cover_file_name"
t.string "jacket_cover_content_type"
t.integer "jacket_cover_file_size"
t.datetime "jacket_cover_updated_at"
t.integer "author_id"
t.integer "age"
t.string "publisher"
t.string "slug"
end
create_table "ckeditor_assets", force: true do |t|
t.string "data_file_name", null: false
t.string "data_content_type"
t.integer "data_file_size"
t.integer "assetable_id"
t.string "assetable_type", limit: 30
t.string "type", limit: 30
t.integer "width"
t.integer "height"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "ckeditor_assets", ["assetable_type", "assetable_id"], name: "idx_ckeditor_assetable", using: :btree
add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], name: "idx_ckeditor_assetable_type", using: :btree
create_table "friendly_id_slugs", force: true do |t|
t.string "slug", null: false
t.integer "sluggable_id", null: false
t.string "sluggable_type", limit: 50
t.string "scope"
t.datetime "created_at"
end
add_index "friendly_id_slugs", ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true, using: :btree
add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", using: :btree
add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree
add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree
create_table "galleries", force: true do |t|
t.string "name"
t.integer "book_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "images", force: true do |t|
t.string "file"
t.string "file_file_name"
t.string "file_content_type"
t.integer "file_file_size"
t.datetime "file_updated_at"
t.integer "gallery_id"
end
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "avatar_file_name"
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.string "username"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
Started POST "/books" for 127.0.0.1 at 2014-09-17 12:22:14 +0100
Processing by BooksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BJhkDx7rCRMIlXQ6T9FskXZe7+fdYxj0qm+VnCaC51w=", "book"=>{"jacket_cover"=>#<ActionDispatch::Http::UploadedFile:0x000001042e5630 @tempfile=#<File:/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/RackMultipart20140917-45239-1jmhle2>, @original_filename="23ebb202a3655c6d0947251cce8625b6.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"book[jacket_cover]\"; filename=\"23ebb202a3655c6d0947251cce8625b6.jpg\"\r\nContent-Type: image/jpeg\r\n">, "title"=>"free book", "synopsis"=>"<p>text</p>\r\n", "body"=>"<p>text</p>\r\n", "age"=>"26", "publisher"=>"Thames & Hudson", "author_attributes"=>{"name"=>"Jonny Forsythe", "biography"=>"<p>the biography</p>\r\n"}, "gallery_attributes"=>{"name"=>"", "book_id"=>""}}, "gallery"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x000001042e4528 @tempfile=#<File:/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/RackMultipart20140917-45239-1bti3g4>, @original_filename="1069-1123-thickbox.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"gallery[image]\"; filename=\"1069-1123-thickbox.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create Book"}
Command :: file -b --mime '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-i5c3h.jpg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g.jpg[0]'
Command :: convert '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g.jpg[0]' -auto-orient -resize "300x300>" '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g20140917-45239-18mq2gx'
Command :: file -b --mime '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g20140917-45239-18mq2gx'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g.jpg[0]'
Command :: convert '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g.jpg[0]' -auto-orient -resize "100x100>" '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g20140917-45239-xkzp3s'
Command :: file -b --mime '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1aa7z5g20140917-45239-xkzp3s'
(0.4ms) BEGIN
Book Exists (0.7ms) SELECT 1 AS one FROM "books" WHERE "books"."slug" = 'free-book' LIMIT 1
Command :: file -b --mime '/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/256178c7c24a3ee9416427a8ff115adc20140917-45239-1o5g0ae.jpg'
Book Exists (1.1ms) SELECT 1 AS one FROM "books" WHERE "books"."title" = 'free book' LIMIT 1
Author Exists (0.8ms) SELECT 1 AS one FROM "authors" WHERE "authors"."name" = 'Jonny Forsythe' LIMIT 1
SQL (1.3ms) INSERT INTO "authors" ("biography", "created_at", "name", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["biography", "<p>the biography</p>\r\n"], ["created_at", Wed, 17 Sep 2014 11:22:16 UTC +00:00], ["name", "Jonny Forsythe"], ["updated_at", Wed, 17 Sep 2014 11:22:16 UTC +00:00]]
SQL (1.3ms) INSERT INTO "books" ("age", "author_id", "body", "created_at", "jacket_cover_content_type", "jacket_cover_file_name", "jacket_cover_file_size", "jacket_cover_updated_at", "publisher", "slug", "synopsis", "title", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING "id" [["age", 26], ["author_id", 42], ["body", "<p>text</p>\r\n"], ["created_at", Wed, 17 Sep 2014 11:22:16 UTC +00:00], ["jacket_cover_content_type", "image/jpeg"], ["jacket_cover_file_name", "23ebb202a3655c6d0947251cce8625b6.jpg"], ["jacket_cover_file_size", 91908], ["jacket_cover_updated_at", Wed, 17 Sep 2014 11:22:14 UTC +00:00], ["publisher", "Thames & Hudson"], ["slug", "free-book"], ["synopsis", "<p>text</p>\r\n"], ["title", "free book"], ["updated_at", Wed, 17 Sep 2014 11:22:16 UTC +00:00]]
SQL (1.1ms) INSERT INTO "galleries" ("book_id", "created_at", "name", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["book_id", 33], ["created_at", Wed, 17 Sep 2014 11:22:16 UTC +00:00], ["name", ""], ["updated_at", Wed, 17 Sep 2014 11:22:16 UTC +00:00]]
(25.0ms) COMMIT
Redirected to http://localhost:3000/books/free-book
Completed 302 Found in 2188ms (ActiveRecord: 31.7ms)
Started GET "/books/free-book" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
Processing by BooksController#show as HTML
Parameters: {"id"=>"free-book"}
Book Load (0.9ms) SELECT "books".* FROM "books" WHERE "books"."slug" = 'free-book' ORDER BY "books"."id" ASC LIMIT 1
CACHE (0.0ms) SELECT "books".* FROM "books" WHERE "books"."slug" = 'free-book' ORDER BY "books"."id" ASC LIMIT 1
Gallery Load (0.6ms) SELECT "galleries".* FROM "galleries" WHERE "galleries"."book_id" = $1 ORDER BY "galleries"."id" ASC LIMIT 1 [["book_id", 33]]
Image Load (0.8ms) SELECT "images".* FROM "images" WHERE "images"."gallery_id" = $1 [["gallery_id", 35]]
Author Load (0.7ms) SELECT "authors".* FROM "authors" WHERE "authors"."id" = $1 ORDER BY "authors"."id" ASC LIMIT 1 [["id", 42]]
Rendered books/show.html.erb within layouts/application (9.0ms)
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Rendered partials/_admin_menu.html.erb (0.1ms)
Rendered partials/_components.html.erb (0.2ms)
Rendered partials/_footer.html.erb (0.1ms)
Completed 200 OK in 95ms (Views: 83.6ms | ActiveRecord: 3.8ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/main.css?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/font-awesome.css?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/ckeditor/init.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/ckeditor/ckeditor.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/vendor/jquery.ui.widget.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/vendor/load-image.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/vendor/canvas-to-blob.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/jquery.iframe-transport.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/vendor/tmpl.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/jquery.fileupload.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/jquery.fileupload-fp.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/jquery.fileupload-ui.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery_nested_form.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/locale.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-fileupload/index.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/authors.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/books.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/ckeditor/basepath.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/ckeditor/config.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/galleries.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/home_controller.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/images.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:16 +0100
[2014-09-17 12:22:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/modernizr.min.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/modules.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/pictures.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/plugins.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/plugins/swiper.slider.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/plugins/transition.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/the_engine_room.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/brown-regular-alt-webfont.woff" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
[2014-09-17 12:22:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/single-book-top.png" for 127.0.0.1 at 2014-09-17 12:22:17 +0100
{"utf8"=>"✓", "authenticity_token"=>"BJhkDx7rCRMIlXQ6T9FskXZe7+fdYxj0qm+VnCaC51w=",
"book"=>{"jacket_cover"=>#<ActionDispatch::Http::UploadedFile:0x00000102707530 @tempfile=#<File:/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/RackMultipart20140917-45239-1gyc95k>, @original_filename="23ebb202a3655c6d0947251cce8625b6.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"book[jacket_cover]\"; filename=\"23ebb202a3655c6d0947251cce8625b6.jpg\"\r\nContent-Type: image/jpeg\r\n">, "title"=>"test 14", "synopsis"=>"<p>text</p>\r\n", "body"=>"<p>text</p>\r\n", "age"=>"19", "publisher"=>"Thames & Hudson",
"author_attributes"=>{"name"=>"mark dunbavan", "biography"=>"<p>him</p>\r\n"},
"gallery_attributes"=>{"name"=>"", "book_id"=>""}}, "gallery"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x000001026ff600 @tempfile=#<File:/var/folders/mf/srx7jt8s2rdg0mn5hr98cvz80000gn/T/RackMultipart20140917-45239-1uy6j0p>, @original_filename="1069-1123-thickbox.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"gallery[image]\"; filename=\"1069-1123-thickbox.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create Book", "action"=>"create", "controller"=>"books"}
@rvanlieshout
Copy link

Parameters: {
  "utf8"=>"✓"
  "authenticity_token"=>"BJhkDx7rCRMIlXQ6T9FskXZe7+fdYxj0qm+VnCaC51w="
  "book"=>{
    "jacket_cover"=>#<ActionDispatch::Http::UploadedFile>
    "title"=>"free book"
    "synopsis"=>"<p>text</p>\r\n"
    "body"=>"<p>text</p>\r\n"
    "age"=>"26"
    "publisher"=>"Thames & Hudson"
    "author_attributes"=>{
    "name"=>"Jonny Forsythe"
      "biography"=>"<p>the biography</p>\r\n"}
      "gallery_attributes"=>{"name"=>""
      "book_id"=>""
    }
  }
  "gallery"=>{
    "image"=>#<ActionDispatch::Http::UploadedFile>
  }
  "commit"=>"Create Book"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment