- Rails 7.0.2
- stimulus js
- importmaps
- dropzone.js
- direct upload ActiveStorage
This is simple implementation of technologies in hobby project of mine built in Rails7 where I need direct upload to S3.
This is simple implementation of technologies in hobby project of mine built in Rails7 where I need direct upload to S3.
/** | |
* Wrapper function with modern JS. May have issues with IE and Safari. | |
* Will preserve event handlers. | |
* @param {ChildNode} elToWrap The element you want to wrap. | |
* @param {ParentNode} wrapper The element to wrap with. | |
*/ | |
const wrap = (elToWrap, wrapper) => { | |
elToWrap.before(wrapper) // so element doesn't move | |
wrapper.append(elToWrap) // automatically moves wrapped element. | |
} |
module WebpackerHelper | |
def page_pack_tags | |
join_paths(application_pack_tags, | |
controller_pack_tags) | |
end | |
def application_pack_tags | |
join_paths(attempt_to_find(:stylesheet, 'application'), | |
attempt_to_find(:javascript, 'application')) | |
end |
class RouteRecognizer | |
attr_reader :paths | |
# To use this inside your app, call: | |
# `RouteRecognizer.new.initial_path_segments` | |
# This returns an array, e.g.: ['assets','blog','team','faq','users'] | |
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)} | |
def initialize |
class EventedClass | |
bind: (event, callback) -> | |
@eventHandlers ||= {} | |
@eventHandlers[event] = [] unless @eventHandlers[event]? | |
@eventHandlers[event].push(callback) | |
return true | |
unbind: (event, callback) -> | |
@eventHandlers ||= {} |