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

  • Home
  • SEARCH
  • 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 6711597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:09:34+00:00 2026-05-26T08:09:34+00:00

In the browser address bar i have http://localhost:3000/comment/index?post_id=6 , i can access the post_id

  • 0

In the browser address bar i have http://localhost:3000/comment/index?post_id=6, i can access the post_id in the index,but when trying to create comment/post in the create action, it says couldnt find post without post ID in the log.What is going on here?thank you in advance.

Comments controller:

def index
  @post=Post.find(params[:post_id])
end

def create
  @post     = Post.find(params[:post_id])
  @comment  = @post.comments.build(params[:comment])
  @comment.save

  respond_with( @comment, :layout => !request.xhr? )          
end

comments/index view:

<%= form_for :comment, :remote => true,
                       :url => { :controller => "comments",
                                 :action     => "create"
                               },
                       :html => { :id => 'new-comment'} do |f|
%>
  <%= f.hidden_field :post_id, :value => @post.id %>
  <%= f.text_area :body %>
  <%= f.submit "post" %>
<% end %>

In the log:

Started POST "/comments" for 127.0.0.1 at 2011-10-17 14:06:36 -0700
  Processing by CommentsController#create as JS
  Parameters: {"utf8"=>"✓",  
    "authenticity_token"=>"cxQm2K2xwsyw0DY2XLNvkcMQI+wM96LpEENbfQqxu5c=",
    "comment"=> {"post_id"=>"6", "body"=>"This is the comment"},
    "commit"=>"post"}
  Completed 404 Not Found in 23ms

  ActiveRecord::RecordNotFound (Couldn't find Post without an ID):
  • 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-26T08:09:35+00:00Added an answer on May 26, 2026 at 8:09 am

    If you take a look in the params hash in your log, you’ll see this:

    { "utf8"=>"✓",
      "authenticity_token"=>"cxQm2K2xwsyw0DY2XLNvkcMQI+wM96LpEENbfQqxu5c=",
      "comment"=> {
          "post_id"=>"6", # <-- there's your post_id
          "body"=>"This is the comment" },
      "commit"=>"post" }
    

    So the post ID is there, but it’s inside the comment hash. So, in your create action, you just need to change to:

    def create
      @post=Post.find(params[:comment][:post_id])
      @comment = @post.comments.build(params[:comment])
      @comment.save
      respond_with( @comment, :layout => !request.xhr? )          
    end
    

    However, you should be able to simplify the create action a bit.

    def create
      @comment = Comment.new(params[:comment])
      @comment.save
      respond_with( @comment, :layout => !request.xhr? )
    end
    

    Since the post_id is in the comment params, the comment will automatically be associated with the post when you create it, without having to look up the record. If you need to access the post in your view, you can use @comment.post.

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

Sidebar

Related Questions

I have seen that typing about:somekeywords in browsers address bar gives some information. What
If i enter a url directly into the address bar of the browser, i
How can the browser tell where I am? Totally based on registered IP address?
I have 2 urls say thinkingmonkey.me and thinkingmonkey.com both have ip-address 127.0.0.1 (A.K.A localhost).
At http://localhost/tmp/ I have a form that asks for the user and password (authentication).
I have URL segment: http://www.site.com/loadContent/contact/4 I want to hide the ID 4 in browser
In the past I have used: import net.rim.blackberry.api.browser.BrowserSession; BrowserSession browserSession = Browser.getDefaultSession(); browserSession.displayPage(http://www.google.com); in
Is it possible to change the URL in the browser address bar directly with
I have this url: http://www.mydomain.com/index.html And want a rule to rewrite the above into
I have a problem I see every so often - I create a CSS

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.