Guest User

Untitled

a guest
Oct 23rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. Started POST "/item/create" for 127.0.0.1 at 2018-10-23 13:08:19 +0300
  2. Processing by ItemsController#create as HTML
  3. Parameters: {"utf8"=>"✓","authenticity_token"=>
  4. "tDpyPV9fPxLUHgRVb4G6P3eMLFUv0hKVnNPJCAcgYISCwjIbjA5bu/iXOy0k6yL
  5. 8+QWXs3MyoJ3lzzyhj3rqkw==", "item"=>{"title"=>"Sample", "description"
  6. =>"Lorem", "attachments_attributes"=>{"0"=>{"media_files"=>[#
  7. <ActionDispatch::Http::UploadedFile:0x007fe818a5ecb0 @tempfile=#
  8. <Tempfile:/var/folders/hq/pr4rt14n7s31v3f6292wtjm00000gn/T/
  9. RackMultipart20181023-1573-1r65sf9.jpg>, @original_filename=
  10. "image1.jpg", @content_type="image/jpeg", @headers="Content-
  11. Disposition: form-data; name="item[attachments_attributes]
  12. [0][media_files][]"; filename="image1.jpg"rnContent-Type:
  13. image/jpegrn">, #<ActionDispatch::Http::UploadedFile
  14. :0x007fe818a5ebe8 @tempfile=#
  15. <Tempfile:/var/folders/hq/pr4rt14n7s31v3f6292wtjm00000gn
  16. /T/RackMultipart20181023-1573-1lbr709.jpg>,
  17. @original_filename="image2.jpg", @content_type=
  18. "image/jpeg", @headers="Content-Disposition: form-data;
  19. name="item[attachments_attributes][0][media_files][]";
  20. filename="image2.jpg"rnContent-Type: image/jpegrn">], "item_id"=>"#
  21. <Item:0x007fe813ef65e8>"}}}, "commit"=>"Create"}
  22.  
  23. Unpermitted parameter: :media_files
  24.  
  25. create_table "attachments", force: :cascade do |t|
  26. t.integer "item_id"
  27. t.string "media_files"
  28. t.string "content_type"
  29. t.datetime "created_at", null: false
  30. t.datetime "updated_at", null: false
  31. end
  32.  
  33. class Item < ApplicationRecord
  34. has_many :attachments, dependent: :destroy
  35. accepts_nested_attributes_for :attachments, allow_destroy: true
  36. end
  37.  
  38. class Attachment < ApplicationRecord
  39. belongs_to :item
  40. mount_uploader :media_files, AttachmentUploader
  41. validates_presence_of :media_files
  42. end
  43.  
  44. def create
  45. params["item"]["attachments_attributes"]["0"]["media_files"].each { |file| @attachment = Attachment.new(:media_files => file)}
  46.  
  47. respond_to do |format|
  48. if @attachment.save
  49. format.html { redirect_back fallback_location: root_path, notice: 'Attachment was successfully created.' }
  50. format.json { render :'shows/show', status: :created, location: @attachment }
  51. else
  52. format.html { render :new }
  53. format.json { render json: @attachment.errors, status: :unprocessable_entity }
  54. end
  55. end
  56. end
  57.  
  58. params.require(:item).permit(:title, :description, attachments_attributes: [:media_files, :item_id, :content_type])
  59.  
  60. <%= form_for(@item, url: items_create_path, :html => { :multipart => true }) do |form| %>
  61. <%= form.text_field :title, id: :item_title, autofocus: true, :class=>"form-control" %>
  62. <%= form.text_area :description, id: :item_description, :class=>"form-control" %>
  63.  
  64. <%= form.fields_for :attachments do |f| %>
  65. <div class="form-group">
  66. <%= f.file_field :media_files, multiple: true, :id=>"upload-photo" %>
  67. <% end %>
  68.  
  69. <%= form.submit "Create", :class=>"btn btn-default" %>
  70. <% end %>
Add Comment
Please, Sign In to add comment