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 1010249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:03:11+00:00 2026-05-16T09:03:11+00:00

I want to develop an ajax functionality for commenting posts in my website. I’ve

  • 0

I want to develop an ajax functionality for commenting posts in my website.

I’ve done this before, but I don’t know why I’m having problems this time. Rails executes Update action from posts_controller, instead of the action called “save_comment”.

This is the relevant line of my routes file:

map.connect "/posts/save_comment", :controller => 'posts', :action => 'save_comment'

This is the view’s code:

<%= javascript_include_tag "prototype" %>

<% if logged_in? %>
  <% remote_form_for :post, PostComment.new, :url => {:action => 'save_comment',:post_id=>inside_list.id}, :html => { :method => :put} do |f| %>
    <p>
      <%= f.label 'Comment' %><br />
      <%= f.text_area :comment, :style=>'height:100px;' %>
    </p>
    <p>
      <%= f.submit 'Publish' %>
    </p>
  <% end %>
<% end %>

The save_comment action looks like this:

  def save_comment
    comment = PostComment.new
    comment.user_id = current_user.id
    comment.post_id = params[:post_id]
    comment.comment = params[:post][:comment]
    comment.save

    post = Post.find(params[:post_id])

    render :update do |page|
        page.replace_html 'dComments', :partial => 'post_comments/inside_list', :object => post
        end
  end

BTW: Is there a neater way for doing this?

  • 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-16T09:03:12+00:00Added an answer on May 16, 2026 at 9:03 am

    You need to define the route method. Also you’re not defining the post parameter.

    map.connect "/posts/:post_id/save_comment", :controller => 'posts', :action => 'save_comment', :method => :post
    

    Following convention you should make the route method => :post, rather than :put. Put requests are generally used for updating existing records, post for creating new. Also how about named routes?

    #routes.rb
    map.save_comment "/posts/:post_id/save_comment", :controller => 'posts', :action => 'save_comment', :method => :post
    
    #view
    <% remote_form_for :post, PostComment.new, :url => save_comment_path(inside_list.id) do |f| %>
    

    Also, guessing here but do you have this defined:

    map.resources :posts
    

    if you do then add the new method

    map.resources :posts, :member => {:save_comment => :post}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop an entirely ajax backend for a website I'm developing, and
I want to develop a website with java but I'm absolute beginner in java
I want develop some web product with using javascript 3d library like three.js But
I want to develop a website where people can find useful informations about other
i was viewing this video and i really want to develop this is PHP
I want to develop a website web chat application like yahoo. Only difference is
I'm developing a web application using .net/c#/jQuery. I want to develop an AJAX function
I am using Eclipse to develop a website in html, css, js, ajax for
I want to develop an Android multiplayer real time game. But I'm still confuse
i want to develop one desktop application using c# sql lite, this application i

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.