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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:58:23+00:00 2026-05-26T06:58:23+00:00

Rails nooby so I don’t know what info to provide. Basically when my show

  • 0

Rails nooby so I don’t know what info to provide. Basically when my show action gets called from the pictures controller a new comment record is inserted. My output looks like this:

Started GET "/pictures/2" for 127.0.0.1 at Wed Oct 19 18:43:24 -0400 2011
  Processing by PicturesController#show as HTML
  Parameters: {"id"=>"2"}
  Picture Load (0.2ms)  SELECT "pictures".* FROM "pictures" WHERE "pictures"."id" = $1     LIMIT 1  [["id", "2"]]
  Comment Load (0.4ms)  SELECT "comments".* FROM "comments" WHERE "comments"."picture_id"     = 2
   (0.2ms)  BEGIN
  SQL (0.7ms)  INSERT INTO "comments" ("comment", "created_at", "downvote", "picture_id",     "updated_at", "upvote") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"  [["comment", nil],     ["created_at", Wed, 19 Oct 2011 22:43:24 UTC +00:00], ["downvote", nil], ["picture_id", 2],     ["updated_at", Wed, 19 Oct 2011 22:43:24 UTC +00:00], ["upvote", nil]]
   (1.1ms)  COMMIT
Rendered pictures/show.html.erb within layouts/application (32.2ms)
Completed 200 OK in 51ms (Views: 41.0ms | ActiveRecord: 7.5ms)

Show Controller:

def show
  @picture = Picture.find(params[:id])
  @comments = @picture.comments
  respond_to do |format|
    format.html # show.html.erb
    format.json { render :json => @picture }
  end
end

Show View:

<p id="notice"><%= notice %></p>

<h2><%= @picture.title %></h2> <br />
    <ul class="media-grid">
     <li>
     <a href="#">
     <%= image_tag @picture.url %>
    </a>
    </li>
  </ul>
<table>
<% @comments.each do |comment| %>
  <tr>
    <td><%= comment.comment %></td>
<td><%= comment.upvote %></td>
<td><%= comment.downvote %></td>
</tr>
<% end %>
</table>
<%= form_for [@picture, @picture.comments.create] do |f| %>
  <%= f.label "Comment:" %><br />
  <%= f.text_field :comment %>
  <%= f.submit %>
<% end %>

<%= link_to 'Back', pictures_path %>

Models:

class Comment < ActiveRecord::Base
  belongs_to :picture
end

class Picture < ActiveRecord::Base
  has_many :comments
end
  • 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-26T06:58:23+00:00Added an answer on May 26, 2026 at 6:58 am

    As far as I know, you dont want to use

    <%= form_for [@picture, @picture.comments.create] do |f| %>
    

    but

    <%= form_for [@picture, @picture.comments.new] do |f| %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm rails noob, and have been confused about sending params from controller to model.
Rails 3 noob here. Currently the code in my controller below is getting the
random rails/ruby questions for a nooby, much appreciated. Confused as to what the second
I'm pulling in the RSS feed from Craigslist into a rails app I'm building.
I am a bit of a noob still with rails, but I am running
Rails uses the concept of migrations to deal with model changes using the ActiveRecord
Rails comes with a handy session hash into which we can cram stuff to
Rails comes with RESTful resources out of the box, but do you use those
Rails introduced some core extensions to Ruby like 3.days.from_now which returns, as you'd expect
Rails is a great platform, but it just doesn't have the history that Perl

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.