Sono bloccato da questa strana uscita nella mia vista Rails. Ecco il mio modello:Perché questa vista delle rotaie sputa un array raw alla fine di un ciclo .each do?
class Comment < ActiveRecord::Base
belongs_to :post
end
Ecco la parte rilevante del mio punto di vista. Ho isolato il problema con questo blocco di codice, in particolare quello che succede dopo l'ultima iterazione e prima della fine del ciclo <% end %>
. Se commento il vero testo stampato in ogni iterazione, l'array raw viene stampato.
<h2>Comments</h2>
<%= @post.comments.each do |comment| %>
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<%= comment.body %>
</p>
<% end %>
Ecco la strana uscita (w/campione commenti.):
Commento: Michael
buon posto.
Commento: Michael
buon posto.
Commento: Michael
test.
Commento: John
è la matrice ancora la stampa divertente?
[#<Comment id: 1, commenter:
"Michael", body: "Good post.",
post_id: 1, created_at: "2011-01-12
03:51:20", updated_at: "2011-01-12
03:51:20">, #<Comment id: 2,
commenter: "Michael", body: "Good
post.", post_id: 1, created_at:
"2011-01-12 03:52:06", updated_at:
"2011-01-12 03:52:06">, #<Comment id:
3, commenter: "Michael", body:
"Test.", post_id: 1, created_at:
"2011-01-12 03:52:24", updated_at:
"2011-01-12 03:52:24">, #<Comment id:
4, commenter: "John", body: "Is the
array still printing funny?", post_id:
1, created_at: "2011-01-12 03:57:20",
updated_at: "2011-01-12 03:57:20">]
Infine, ecco come il registro di sviluppo sta leggendo. Sembrano tutti così.
Started GET "/posts/1" for 127.0.0.1 at 2011-01-11 22:01:52 -0600
Processing by PostsController#show as HTML
Parameters: {"id"=>"1"}
[1m[36mPost Load (0.1ms)[0m [1mSELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1) LIMIT 1[0m
[1m[35mComment Load (0.3ms)[0m SELECT "comments".* FROM "comments" WHERE ("comments".post_id = 1)
Rendered posts/show.html.erb within layouts/application (57.5ms)
Completed 200 OK in 73ms (Views: 61.1ms | ActiveRecord: 0.4ms)
Qualcuno sa che cosa sta causando questo? Se questo fosse PHP, direi che ho lasciato un print_r da qualche parte nel codice. Ma non lo è e non ho fatto niente del genere.
Grazie. Non ho capito questa funzionalità fino ad ora. Utile! – Michael
Grazie, ha avuto lo stesso identico problema. – tpower
Grazie, anch'io ho affrontato la stessa situazione. – Adnan