2011-10-19 44 views
1

Rails nooby,所以我不知道提供什麼信息。基本上,當我的演出動作從畫面控制器被調用時,插入一條新的評論記錄。我的輸出是這樣的:爲什麼我的導軌在選擇後顯示動作創建新記錄?

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) 

顯示控制器:

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 

顯示視圖:

<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 %> 

型號:

class Comment < ActiveRecord::Base 
    belongs_to :picture 
end 

class Picture < ActiveRecord::Base 
    has_many :comments 
end 
+0

發表您的觀點顯示,畫面和評論模型.... – DGM

回答

2

據我所知,你不想要使用

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

<%= form_for [@picture, @picture.comments.new] do |f| %> 
相關問題