Executive Summary
-
Question 1: What is the value of providing local variables to a render, when they can access the instance objects in the controller?
-
Issue: I can NOT run a ruby loop within my _error.js.erb file. The goal of this loop is to provide DIRECT output to a $("#error_explanation") id regarding all of the
-
I was able to run the various other jquery commands as illustrated below.
-
I am able to run straight JQUERY commands leveraging ruby.
Dear Friends,
In my create controller, i have a
format.js { render "_error.js.erb", locals: {post: @post, errors: @post.errors.messages} }
In my VIEW _error.js.erb, i have 3 JQUERY queries, two of them work, but the third does not work.
This Works. $("#error_explanation").append('<%= j pluralize(post.errors.count, "error") %> prohibited this secret from being saved: <p>');
This Works. $("#error_explanation").append('<%= post.errors.full_messages_for(:title) %>');
This Does NOT Work. $("#error_explanation").append('
<% post.errors.messages.each do |error| %>
<%= j error %>
<% end %>');
I can only assume that it is because of my loop? Can I not perform loops in my javascript (js.erb) code?
Aucun commentaire:
Enregistrer un commentaire