Monday, March 13, 2023
HomeRuby On RailsEmbedded Kinds from the ground up with StimulusJS

Embedded Kinds from the ground up with StimulusJS


 # Terminal

. treasure set up rails -- pre

. rails g scaffold todo_list name

. rails g design job todo_list: belongs_to summary

. thread include stimulation
 # models/todo _ list.rb

. course TodoList < ApplicationRecord

. has_many: jobs, reliant:: damage

. accepts_nested_attributes_for: jobs, allow_destroy: real, reject_if: proc attr['description'] space? 

. end

#
models/task. rb(* )
. course Job < ApplicationRecord 
.
belongs_to: todo_list

. end  # todo_lists_controller. rb
 
. def todo_list_params

. params.require(: todo_list). license(: name, tasks_attributes: )

. end [:_destroy, :id, :description] # app/javascript/packs/ application.js


. import {Application}
from" stimulation" 
. import {definitionsFromContext}
.

from" stimulus/webpack-helpers" 
. 
. const application= Application.start()

. const context = require.context("./ controllers", real,/. js$/)

. application.load( definitionsFromContext( context)) # app/javascript/controllers/ nested_form_controller. js

. import {Controller}

from"
stimulation" 
. 
. export default course expands Controller {

. fixed targets = 


.

. add_association( occasion) {

. event.preventDefault() 
. var material= this.templateTarget.innerHTML.replace(/ TEMPLATE_RECORD/ g, brand-new Day(). valueOf()) 
.
this.add _ itemTarget.insertAdjacentHTML(' beforebegin', material)

.

} 
. 
. remove_association( occasion) {

. event.preventDefault() 
. allow product= event.target.closest(".
nested-fields") 
.
item.querySelector(" input["add_item", "template"]"). worth = 1 
.
item.style.display=' none' 
.} 
.
}>.[name*='_destroy']<# todo_lists/ _ form.html.erb 
.<
 < h1 >  Jobs  
. < div data-controller=">nested-form"<> 
  < layout data-target=">nested-form. layout" > 
   
.  
.
< 
.  
. 
.   
.  
.

< 
. 
.
< div 
  
.<  
. 
# _ task_fields. < div course=">nested-fields" ><
  < div course=" form-group" >  
< 
. <
.
<< little >  
. 

<.


.
< 
.
.

RELATED ARTICLES

Most Popular

Recent Comments