Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:20:16+00:00 2026-05-23T14:20:16+00:00

Update, going off what Frank wrote below: In my post’s show view I have:

  • 0

Update, going off what Frank wrote below:

In my post’s show view I have:

<span id="commentsPartial">
<%= render 'comments' %>
</span>

In the comments partial I have:

<% @comments.each do |comment| %>
    <%= comment.description %>
<% end %>
<br/>
<%= render '/comments/form' %>

In my form partial I have:

<%= form_for [@comment], :remote => true do |f| %>
  <% if @comment.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>

      <ul>
      <% @comment.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.text_area :description, :class => "forms", :style => "width:80%;height:120px;"%>
  </div>
  <div class="actions" style="margin-top:10px;">
    <%= f.hidden_field :user_id, :value => current_user.id %>
    <%= f.hidden_field :post_id, :value => @post.id %>
    <%= f.submit :class => "button-style" %>
  </div>
<% end %>

My views/comments/create.js.erb page has:

$("#commentsPartial").html("<%= escape_javascript(render('comments')) %>");

When I submit a new comment – it is successfully created. The page however remains static. When I watch in firebug, I see the comment is created, and there is a get called on the post which returns a success – even though the page doesn’t update… very confused

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:20:16+00:00Added an answer on May 23, 2026 at 2:20 pm

    I think you are following the wrong approach and think too much jQuery like instead of the “rails way” to do it.
    You can just pass the option :remote => :true to your form_tag or form_for in order to tell rails to use ajax instead.

    Probably you want to nest the comment into another Model, (google: nested routes), and then have an file in

    app/views/comments/create.js.erb whcih is something like this:

    $("#comments").prepend("<%= escape_javascript render(@comment) %>");  
    $('#comments_count').html('<%= pluralize(@comment.image.comments.count, "Comment") %>');  
    $("#comment_body").val("");
    $("#comments .comment_body:first").effect("highlight", { color:"#D3ECF4"}, 3000);
    

    here you specify what should be done to update the view on success.

    in your controller you can just use:

      def create
        @comment = Comment.create!(params[:comment])  
      end
    

    and for the view something like:

    <div id="comments">
        <%= render @comments %>
    </div>
    
    
    <% form_for [@image, Comment.new], :remote => true  do |f| %>
     <%= render 'comment_fields', :f => f %>
    <% end %>
    

    supposed you want to comment on an image.

    my _comment_fields.html.erb partial then looks like this:

    <p id="new_comment" class="add_comment">
      <%= f.hidden_field :user_id, :value => current_user.id %>
      <%= f.hidden_field :image_id, :value => @image.id %>
      <%= f.label :body, "leave a comment" %><br />
      <%= f.text_area :body, :rows => 5, :cols => 25 %>
    </p>
    
    <p>
      <%= f.submit "Add Comment" %>
    </p>
    

    This is rails’ way to handle javascript unobstrusively. A good ressource on this is this screencast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Going off the documentation here: http://docs.djangoproject.com/en/dev/topics/db/sql/ >>>cursor = connection.cursor() >>>cursor.execute(UPDATE bar SET foo =
I am going nuts here trying to resolve a cascading update/delete issue :-) I
I'm going to create widget which needs to update its content every minute (it
Update: Solved, with code I got it working, see my answer below for the
I have a table based off Sam's Teach Yourself iOS Development's FlowerViewController , that,
I am developing a project that lately have been taking off with increased popularity.
I am getting below exception when i am going to enter record in a
Update Just for future reference, I'm going to list all of the statistics that
I have a simple form that is used to update an entity in my
I have a peculiar issue I'm dealing with. I'll start off vague and if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.