Basically, I have a single page TODOAPP that is displayed in Rails on Index.html.erb and I'm trying to render the instantiated TODO objects through index.js.erb because they have a form attached to each of them that needs an authenticity token from a rails helper. Rendering the TODOs through/in Javascript is a necessity.
My solution was to try and append the todos to the Index.html.erb View through setting render "index.js.erb" in the index and calling a partial that would render then in ruby and then run ('<%= j render 'index.html.erb' %>). However, that expects an _index partial, and just trying to append or even run anything directly in index.js.erb actually results in that page itself being rendered.
Of course, I understand this is a routing issue, but I can't find anyway to render the TODO objects to the DOM through/in JS and include the authenticity token in the form they're wrapped in, since appending a form in the dom through jquery in the .js file won't allow for the token to be included.
I'd really appreciate any possible insight you might have because I've exhausted online searches and YouTube video at this point. My index controller action is:
def index
@todo = Todo.new
@todos = Todo.all
respond_to do |format|
format.html { render 'index.js.erb' }
format.json { render :json => @todos }
format.js { render 'form.js.erb' }
end
end
And the GITHUB Repo is: https://github.com/jwolfe890/todoapp/blob/master/app/assets/javascripts/todo.js
Thank you immensely for any insight!