Skip to content

Instantly share code, notes, and snippets.

@adamcrown
Last active September 15, 2016 16:48
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 adamcrown/2ee2934b4d1d6e18bfb51640a4896d27 to your computer and use it in GitHub Desktop.
Save adamcrown/2ee2934b4d1d6e18bfb51640a4896d27 to your computer and use it in GitHub Desktop.
Vue.js for accets_nested_attributes_for
#vue-job-requirements-app data-job-requirements=job_requirements_json(@job_role.job_requirements)
.form-group v-for="req in requirements"
input type="hidden" name="job_role[job_requirements_attributes][{{ $index }}][id]" value="{{ req.id }}"
input type="hidden" name="job_role[job_requirements_attributes][{{ $index }}][_destroy]" value="{{ req._destroy }}"
.input-group v-if="req._destroy != '1'" transition="fade-out"
input.form-control type="text" name="job_role[job_requirements_attributes][{{ $index }}][description]" value="{{ req.description }}"
.input-group-addon v-on:click="removeRequirement($index)"
i.fa.fa-times.text-danger
button.btn.btn-success.btn-xs type="button" v-on:click="addRequirement()"
i.fa.fa-plus
if($('#vue-job-requirements-app').length > 0) {
new Vue({
el: '#vue-job-requirements-app',
data: {
newRequirement: { id: null, description: '', _destroy: null },
requirements: $('#vue-job-requirements-app').data('job-requirements')
},
methods: {
addRequirement: function () {
this.requirements.push(this.newRequirement)
},
removeRequirement: function (index) {
this.requirements.$set(index, $.extend({}, this.requirements[index], {_destroy: 1}))
}
}
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment