Skip to content

Instantly share code, notes, and snippets.

@ElMassimo
Last active March 13, 2021 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElMassimo/cab56e64e20ff797f3054b661a883646 to your computer and use it in GitHub Desktop.
Save ElMassimo/cab56e64e20ff797f3054b661a883646 to your computer and use it in GitHub Desktop.
js_from_routes: Example on how to generate request helpers for jQuery instead of fetch or axios
//
// DO NOT MODIFY: This file was automatically generated by JsFromRoutes.
import { formatUrl } from '@js-from-routes/core'
export default {
<% routes.each_with_index do |route, index| %>
<% if index > 0 %><%= "\n" %><% end
%> <%= route.helper %>: options =>
<% unless route.export == :path_only
%>$.<%= route.verb %>({ url: <% end %>formatUrl('<%= route.path %>', options)<%
unless route.export == :path_only %>, ...options })<% end %>,
<% end %>
}
// JsFromRoutes CacheKey 51392094fd67182442e4e49fb7820825
//
// DO NOT MODIFY: This file was automatically generated by JsFromRoutes.
import { formatUrl } from '@helpers/UrlHelper'
export default {
downloadPath: options =>
formatUrl('/video_clips/:id/download', options),
addToPlaylist: options =>
$.patch({ url: formatUrl('/video_clips/:id/add_to_playlist', options), ...options }),
removeFromPlaylist: options =>
$.patch({ url: formatUrl('/video_clips/:id/remove_from_playlist', options), ...options }),
trending: options =>
$.get({ url: formatUrl('/video_clips/trending', options), ...options }),
thumbnail: options =>
$.get({ url: formatUrl('/video_clips/:id/thumbnail/:thumbnail_id', options), ...options }),
create: options =>
$.post({ url: formatUrl('/video_clips', options), ...options }),
new: options =>
$.get({ url: formatUrl('/video_clips/new', options), ...options }),
edit: options =>
$.get({ url: formatUrl('/video_clips/:id/edit', options), ...options }),
update: options =>
$.patch({ url: formatUrl('/video_clips/:id', options), ...options }),
destroy: options =>
$.delete({ url: formatUrl('/video_clips/:id', options), ...options }),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment