Skip to content

Instantly share code, notes, and snippets.

@bchase
Last active October 10, 2018 22:15
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 bchase/d7de221b4db6633669d360237d3deaec to your computer and use it in GitHub Desktop.
Save bchase/d7de221b4db6633669d360237d3deaec to your computer and use it in GitHub Desktop.
// app/assets/javascripts/App.js
class App {
static initJobShow() {
$(document).ready(function(){
let user_id = $(".user-id").data("id")
let job_id = $(".job-id").data("id")
$.get(`/users/${user_id}/jobs/${job_id}.json`, function(data) {
let job = new Job(date, user_id)
$('#foo').append(JobView.renderJobShow(job))
})
})
}
static initJobIndex() {
// ...
}
}
// app/assets/javascripts/job/view/JobView.js
class JobView {
static renderJobShow(job) {
$('<div>', {}, [ renderJobTitle(job), ... ])
}
static renderJobTitle(job) { ... }
static renderJobAppliedBtn(job) { ... }
}
// ///// app/views/layout/application.html.erb /////
//
// ...
//
// = javascript_tag 'App.js' # ^ our `App` class above
// ///// app/views/jobs/show.html.erb /////
//
// ...
//
// <script type='text/javascript'>
// App.initJobShow()
// </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment