Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery post to Rails
    primarykey
    data
    text
    <p>My setup: Rails 3.0.9, Ruby 1.9.2, jQuery 1.6.2</p> <p>I have a form that shows multiple photos and comments for a user and I wish to implement inline commenting.</p> <pre><code>&lt;div id="newsfeed"&gt; &lt;div&gt; &lt;div class="photo_title"&gt;Summer 2011&lt;/div&gt; &lt;div class="newsfeed_photo"&gt; &lt;a href="..." /&gt;&lt;/a&gt; &lt;/div&gt; &lt;textarea class="comment_box"&gt;Write a comment...&lt;/textarea&gt; &lt;/div&gt; &lt;div&gt; &lt;div class="comment_title"&gt;Seeing a movie&lt;/div&gt; &lt;textarea class="comment_box"&gt;Write a comment...&lt;/textarea&gt; &lt;/div&gt; </code></pre> <p>I want to submit an AJAX post upon the user hitting the enter key in the textarea field. Here's the javascript (incomplete) that I have so far</p> <pre><code> $('#newsfeed').delegate('.comment_box', 'keydown', function (event){ event.preventDefault(); $.post('/sub_comments', ...); }); </code></pre> <p>I'm using the <code>delegate</code> method because <code>&lt;div id='newsfeed'&gt;</code> contents could be replaced with another AJAX call. What I need is the syntax for jQuery <code>post</code> method assuming I need to pass some form params like say <code>photo_id</code>, etc. Assume that I have a way to access the values for the params, what's the syntax for the <code>post</code> call to creating params the way Rails expect them</p> <p>Here's the standard Rails bits</p> <pre><code>sub_comments_controller.rb def new @sub_comment = SubComment.new respond_to do |format| format.html # new.html.erb format.js end end </code></pre> <p>Also I don't want to use the usual <code>&lt;%= form_for(@sub_comment, :remote =&gt; true) do |f| %&gt;</code> for each and every inline comment I could add. I have also taken a look at Ryan Bates's <a href="http://railscasts.com/episodes/136-jquery" rel="noreferrer">railscast</a> but the code looks outdated.</p>
    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.
 

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