Ruby on rails 非预期布局输出-RoR 3.0.1.1
我最近开始学习RoR。我的问题是,当我调用html.erb文件中的post时,会得到一个意外的输出Ruby on rails 非预期布局输出-RoR 3.0.1.1,ruby-on-rails,layout,controller,Ruby On Rails,Layout,Controller,我最近开始学习RoR。我的问题是,当我调用html.erb文件中的post时,会得到一个意外的输出 1 class TestSiteController < ApplicationController 2 def Home 3 @greeting = 'Hello' 4 @posts = Post.all 5 6 respond_to do |format| 7 format.html 8 format.xml { rende
1 class TestSiteController < ApplicationController
2 def Home
3 @greeting = 'Hello'
4 @posts = Post.all
5
6 respond_to do |format|
7 format.html
8 format.xml { render :xml => @posts }
9 format.json { render :json => @posts }
10 end
11 end
1 <h1>testsite#home</h1>
2 <%= link_to "contact", about_us_path %>
3
4 <table>
5 <%= @posts.each do |p| %>
6 <tr>
7 <td><%= p.topic %></td>
8 <td><%= p.post %> </td>
9 </tr>
10 <% end %>
11 </table>
//Unwanted array
[#<Post id: 1, topic: "Rainy Day", post: "Today was a rainy day", created_at: "2012-03-29 21:22:43", updated_at: "2012-03-29 21:22:43">, #<Post id: 2, topic: "It works!", post: "Saving data from the rails console to the mysql db ...", created_at: "2012-03-29 21:25:18", updated_at: "2012-03-29 21:25:18">]
//List start
Rainy Day Today was a rainy day
It works! Saving data from the rails console to the mysql db work! I'm so ecstatic! :D
1类TestSiteController@posts}
9 format.json{render:json=>@posts}
10端
11完
1个测试站点#主页
2.
3.
4.
5.
6.
7.
8.
9
10
11
我在下面得到了我想要的帖子列表,但在列表的顶部是一个我不想输出的帖子数组。有人知道为什么会这样吗
//Unwanted array
[#<Post id: 1, topic: "Rainy Day", post: "Today was a rainy day", created_at: "2012-03-29 21:22:43", updated_at: "2012-03-29 21:22:43">, #<Post id: 2, topic: "It works!", post: "Saving data from the rails console to the mysql db ...", created_at: "2012-03-29 21:25:18", updated_at: "2012-03-29 21:25:18">]
//List start
Rainy Day Today was a rainy day
It works! Saving data from the rails console to the mysql db work! I'm so ecstatic! :D
以下是输出:
//Unwanted array
[#<Post id: 1, topic: "Rainy Day", post: "Today was a rainy day", created_at: "2012-03-29 21:22:43", updated_at: "2012-03-29 21:22:43">, #<Post id: 2, topic: "It works!", post: "Saving data from the rails console to the mysql db ...", created_at: "2012-03-29 21:25:18", updated_at: "2012-03-29 21:25:18">]
//List start
Rainy Day Today was a rainy day
It works! Saving data from the rails console to the mysql db work! I'm so ecstatic! :D
//不需要的数组
[#, #]
//列表开始
雨天今天是雨天
它起作用了!将数据从rails控制台保存到mysql数据库工作!我太高兴了D
您正在输出@posts
的内容,因为您正在使用哇,这完全解决了我的问题!谢谢