Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Last active December 5, 2018 15:09
Show Gist options
  • Save staycreativedesign/a9e9452a2bdf331b3d2b5595150e4ba8 to your computer and use it in GitHub Desktop.
Save staycreativedesign/a9e9452a2bdf331b3d2b5595150e4ba8 to your computer and use it in GitHub Desktop.
= f.fields_for :documents_attributes do |ff|
= ff.hidden_field :graphic, class: "upload-hidden"
Processing by Admin::LessonsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I3NfaupPeavweIfWD3bxxXpev3+46prtirGNxx88Fs/FGWBXuVO8GFu4qpFYxJFVugxhEIpFpd9amPbOgYIffg==", "lesson"=>{"title"=>"lesson 1", "video_link"=>"lesson 1", "documents_attributes"=>{"graphic"=>""}, "description"=>""}, "uploading_image"=>"", "commit"=>"Create Lesson", "course_id"=>"foobar"}
Membership Load (0.3ms) SELECT "memberships".* FROM "memberships" WHERE "memberships"."id" = $1 LIMIT $2 [["id", 51], ["LIMIT", 1]]
Course Load (0.3ms) SELECT "courses".* FROM "courses" WHERE "courses"."slug" = $1 LIMIT $2 [["slug", "foobar"], ["LIMIT", 1]]
Completed 500 Internal Server Error in 11ms (ActiveRecord: 0.6ms)
TypeError (no implicit conversion of Symbol into Integer):
app/controllers/admin/lessons_controller.rb:18:in `create'
Using Shrine Gem
# == Schema Information
#
# Table name: documents
#
# id :bigint(8) not null, primary key
# graphic_data :text
# documentable_type :string
# documentable_id :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
#
class Document < ApplicationRecord
belongs_to :documentable, polymorphic: true, optional: true
include FileUploader::Attachment.new(:graphic)
end
class FileUploader < Shrine
plugin :activerecord
plugin :cached_attachment_data # for retaining the cached file across form redisplays
plugin :restore_cached_data # re-extract metadata when attaching a cached file
plugin :determine_mime_type
plugin :remove_attachment
plugin :delete_raw
end
def lesson_params
params.require(:lesson).permit(:video_link, :title, :slug, :description, documents_attributes: [:graphic])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment