Ruby on rails 如何在视图中输出RubyonRails中所需的变量值?

Ruby on rails 如何在视图中输出RubyonRails中所需的变量值?,ruby-on-rails,ruby,model-view-controller,methods,for-loop,Ruby On Rails,Ruby,Model View Controller,Methods,For Loop,现在,在视图文件夹中的application.html.erb中,我编写了以下内容 <p>List of all post IDs: <%= Post.all.each {|i| print i.id } %></p> 我希望它只输出每个帖子的post.id。但它却显示了这一点 List of all post IDs: [#<Post id: 1, title: "Our First Post", content: "Content for our

现在,在视图文件夹中的application.html.erb中,我编写了以下内容

<p>List of all post IDs: <%= Post.all.each {|i| print i.id } %></p>
我希望它只输出每个帖子的post.id。但它却显示了这一点

List of all post IDs: [#<Post id: 1, title: "Our First Post", content: "Content for our first post", created_at: "2012-11-24 11:22:02", updated_at: "2012-11-26 17:40:54", user_id: 1>, #<Post id: 3, title: "Our Second Post", content: "Content for our second post", created_at: "2012-11-24 11:51:32", updated_at: "2012-11-26 17:41:33", user_id: 2>, #<Post id: 8, title: "Our Second Post", content: "Content of Our mandatory Second Post", created_at: "2012-11-24 19:42:02", updated_at: "2012-11-27 20:46:57", user_id: 1>, #<Post id: 10, title: "C Post", content: "Hi I'm Cee nice to meet you", created_at: "2012-11-26 17:51:20", updated_at: "2012-11-26 17:51:20", user_id: 3>, #<Post id: 20, title: "11", content: "11", created_at: "2012-11-27 19:58:48", updated_at: "2012-11-27 19:58:48", user_id: 4>, #<Post id: 21, title: "22", content: "22", created_at: "2012-11-27 19:58:53", updated_at: "2012-11-27 19:58:53", user_id: 4>, #<Post id: 25, title: "I'm Super Singha!", content: "Yessar!!!", created_at: "2012-11-27 20:45:07", updated_at: "2012-11-27 20:45:07", user_id: 6>, #<Post id: 26, title: "Should this be a blog or a forums or a whatever-wha...", content: ";asljdfi;asfi;asdf;lasbfurbofioboboeifhosdsdbvisbvw...", created_at: "2012-11-27 20:46:28", updated_at: "2012-12-02 14:17:14", user_id: 1>, #<Post id: 27, title: "Hullow", content: "Yoyoyo", created_at: "2012-11-30 07:35:38", updated_at: "2012-11-30 07:35:54", user_id: 6>, #<Post id: 649, title: "um", content: "hey", created_at: "2012-11-30 12:20:58", updated_at: "2012-11-30 12:20:58", user_id: 2>, #<Post id: 82692, title: "LALALALAL", content: "hiopsdahfiosadhfioahfio", created_at: "2012-12-02 13:59:04", updated_at: "2012-12-02 14:22:41", user_id: 2>, #<Post id: 82693, title: "ggg", content: "fff", created_at: "2012-12-02 14:29:42", updated_at: "2012-12-02 14:29:42", user_id: 2>, #<Post id: 82694, title: "sick", content: "sick", created_at: "2012-12-02 14:41:32", updated_at: "2012-12-02 14:41:32", user_id: 5>]
我试过,用印刷代替印刷,这也不行

进一步:我也想做一个链接到每个帖子展示页面从预期的结果,我如何才能实现这一点

这是我的回购协议,这是heroku网站:


谢谢。

这里的问题在于如何使用ERB标签:

<p>List of all post IDs: 
</p>
<%= Post.all.each do |e| %>
  <p>
    <%= e.Id %>
  <p>
  <%= link_to "Show", e %> 
<% end %>
<%= Post.all.each {|i| print i.id } %>

你读过关于Rails视图的教程吗?不,我只学了一周的Rails。但是,嘿,现在如果我像这样被否决,我将永远不会达到15%的票数来超过任何人来表达我的感激之情。谢谢你的回答。
<p>List of all post IDs: 
  <% Post.all.each |post| do %>
    <%= link_to post.id, post_path(post) %>
  <% end %>
</p>