Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusing rails div id naming
    primarykey
    data
    text
    <p>I have started using jQuery and rails. I have made a simple form that submits to the database and updates the page without reloading with ajax.</p> <p>In my jQuery functions I used $"#new_comment" for the id name (in my application.js and create.js.erb files) but on my places/show view file, I named the div "add_comment" and it works..</p> <p>I renamed it new_comment and it breaks! Can someone explain it please? I get an error: "no action responded to 1"</p> <p>My function in my controller is "create".</p> <pre><code>#views/places/show.html.erb &lt;div id="new_comment" style="display:none"&gt; #form goes here &lt;/div&gt; #application.js jQuery.fn.submitWithAjax = function(){ $("#new_comment").submit(function() { $.post($(this).attr("action"), $(this).serialize(), null, "script"); return false; }) }; $(document).ready(function() { $("new_comment").submitWithAjax(); }) #create.js.erb $("#new_comment").before('&lt;div id="flash_notice"&gt;&lt;%= escape_javascript(flash.delete(:notice)) %&gt;&lt;/div&gt;'); $("#comments_count").html("&lt;%= pluralize(@comment.place.comments.count, 'suggestion') %&gt;"); $("#comments").append("&lt;%= escape_javascript(render(:partial =&gt; @comment)) %&gt;"); $("#new_comment")[0].reset(); #comments_controller.rb def create @place = Place.find(params[:place_id]) @comment = @place.comments.create!(params[:comment]) flash[:notice] = "Thanks for your suggestion. Remember to share with friends!" respond_to do |format| format.html {redirect_to place_comments_path(@place)} format.js end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload