您好我是Ruby on Rails的新手。我的代码运行良好。我的问题是网页上有一些文字显示,我不知道它来自哪里。 这是它的截图: http://awesomescreenshot.com/0f32dhw7f4
这是我的添加控制器
class AddsController < ApplicationController
def new
@add = Add.new
end
def create
@add = Add.new(params.require(:add).permit(:first_name, :last_name, :email))
if @add.save
redirect_to(:controller=>'home')
else
render 'new'
end
end
def edit
@add = Add.find(params[:id])
end
def update
@add = Add.find(params[:id])
if @add.update(params.require(:add).permit(:first_name, :last_name, :email))
redirect_to(:controller=>'home')
else
render 'edit'
end
end
def destroy
@add = Add.find(params[:id])
@add.destroy
redirect_to(:controller=>'home')
end
end
这是我的app / views / home文件
<ul id="nav">
<li><%= link_to "Home", controller: "home" %></li>
<li><%= link_to "Products", controller: "products" %></li>
</ul>
<div class="clear"></div>
<h1>Lists</h1>
<%= link_to "Add", new_add_path, :class=> 'btn btn-success' %>
<br />
<br />
<table class="table">
<tr>
<th>First Name </th>
<th>Last Name </th>
<th>Email </th>
<th>Options </th>
</tr>
<%= @adds.each do |adds| %>
<tr>
<td><%= adds.first_name%></td>
<td><%= adds.last_name %></td>
<td><%= adds.email %></td>
<td><%= link_to "Edit", edit_add_path(adds) %> |
<%= link_to "Delete", add_path(adds),
method: :delete, data:{confirm: 'Are you sure you want to delete this?'} %>
</td>
</tr>
<% end %>
</table>
我的家庭控制器
class HomeController < ApplicationController
def index
@adds = Add.all
end
end
有人可以告诉我这个吗?
答案 0 :(得分:1)
在迭代数组的视图中,您使用了&lt;%= @adds%&gt;更改代码的迭代部分,如下所示
<% @adds.each do |adds| %>
<tr>
<td><%= adds.first_name%></td>
<td><%= adds.last_name %></td>
<td><%= adds.email %></td>
<td><%= link_to "Edit", edit_add_path(adds) %> |
<%= link_to "Delete", add_path(adds),
method: :delete, data:{confirm: 'Are you sure you want to delete this?'} %>
</td>
</tr>
<% end %>
答案 1 :(得分:0)
更改此
<%= @adds.each do |adds| %>
要
<% @adds.each do |adds| %>
答案 2 :(得分:0)