Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Started POST "/item/create" for 127.0.0.1 at 2018-10-23 13:08:19 +0300
- Processing by ItemsController#create as HTML
- Parameters: {"utf8"=>"✓","authenticity_token"=>
- "tDpyPV9fPxLUHgRVb4G6P3eMLFUv0hKVnNPJCAcgYISCwjIbjA5bu/iXOy0k6yL
- 8+QWXs3MyoJ3lzzyhj3rqkw==", "item"=>{"title"=>"Sample", "description"
- =>"Lorem", "attachments_attributes"=>{"0"=>{"media_files"=>[#
- <ActionDispatch::Http::UploadedFile:0x007fe818a5ecb0 @tempfile=#
- <Tempfile:/var/folders/hq/pr4rt14n7s31v3f6292wtjm00000gn/T/
- RackMultipart20181023-1573-1r65sf9.jpg>, @original_filename=
- "image1.jpg", @content_type="image/jpeg", @headers="Content-
- Disposition: form-data; name="item[attachments_attributes]
- [0][media_files][]"; filename="image1.jpg"rnContent-Type:
- image/jpegrn">, #<ActionDispatch::Http::UploadedFile
- :0x007fe818a5ebe8 @tempfile=#
- <Tempfile:/var/folders/hq/pr4rt14n7s31v3f6292wtjm00000gn
- /T/RackMultipart20181023-1573-1lbr709.jpg>,
- @original_filename="image2.jpg", @content_type=
- "image/jpeg", @headers="Content-Disposition: form-data;
- name="item[attachments_attributes][0][media_files][]";
- filename="image2.jpg"rnContent-Type: image/jpegrn">], "item_id"=>"#
- <Item:0x007fe813ef65e8>"}}}, "commit"=>"Create"}
- Unpermitted parameter: :media_files
- create_table "attachments", force: :cascade do |t|
- t.integer "item_id"
- t.string "media_files"
- t.string "content_type"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- end
- class Item < ApplicationRecord
- has_many :attachments, dependent: :destroy
- accepts_nested_attributes_for :attachments, allow_destroy: true
- end
- class Attachment < ApplicationRecord
- belongs_to :item
- mount_uploader :media_files, AttachmentUploader
- validates_presence_of :media_files
- end
- def create
- params["item"]["attachments_attributes"]["0"]["media_files"].each { |file| @attachment = Attachment.new(:media_files => file)}
- respond_to do |format|
- if @attachment.save
- format.html { redirect_back fallback_location: root_path, notice: 'Attachment was successfully created.' }
- format.json { render :'shows/show', status: :created, location: @attachment }
- else
- format.html { render :new }
- format.json { render json: @attachment.errors, status: :unprocessable_entity }
- end
- end
- end
- params.require(:item).permit(:title, :description, attachments_attributes: [:media_files, :item_id, :content_type])
- <%= form_for(@item, url: items_create_path, :html => { :multipart => true }) do |form| %>
- <%= form.text_field :title, id: :item_title, autofocus: true, :class=>"form-control" %>
- <%= form.text_area :description, id: :item_description, :class=>"form-control" %>
- <%= form.fields_for :attachments do |f| %>
- <div class="form-group">
- <%= f.file_field :media_files, multiple: true, :id=>"upload-photo" %>
- <% end %>
- <%= form.submit "Create", :class=>"btn btn-default" %>
- <% end %>
Add Comment
Please, Sign In to add comment