ruby on rails - Why is everything in my database (create and update times, topic_id, post_id) displaying in my view? -
i'm new programming , have been learning ruby on rails 6 weeks. i've added commenting functionality app, , while comments beingness displayed properly, else in (sqlite3) database associated comment - created_at, updated_at, comment_id, post_id. partial displays comments has next code:
<%= form_for [post, comment] |f| %> <p><%= @comments.each |comment| %></p> <small> <p><%= comment.body %></p> </small> <% end %> <% end %>
as can see, i'm trying display comment body, i'm displaying everything.
here create method comments controller:
def create @post = post.find(params[:post_id]) @comment = current_user.comments.build(params_comment) @comment.post = @post authorize @comment if @comment.save flash[:notice] = "comment created" redirect_to [@post.topic, @post] else flash[:error] = "comment failed save" redirect_to [@post.topic, @post] end end end
i'm not sure why everyting displaying if i'm calling .body on comment. i've researched problem haven't found anything. help appreciated.
here prepare :-
<%= form_for [post, comment] |f| %> <!-- here removed `=` `<%` %> --> <p><% @comments.each |comment| %></p> <small> <p><%= comment.body %></p> </small> <% end %> <% end %>
#each
returns collection when block finished total iteration. now, used <%= ..%>
, printing homecoming value of #each
. if <%..%>
, wouldn't print although @comments.each
still returning @comments
collection.
ruby-on-rails sqlite3 erb
No comments:
Post a Comment