0
我剛剛完成了Rails的Getting Started guide,並且除了在Index視圖中打印的這個神祕條目外,其他所有工作都很完美,如下所示。我一直在試圖找到原因,但我沒有找到適合谷歌這個問題的條款。 Rails模型打印字符串與所有模型數據的索引視圖
Index.html.erb
<h1>Index</h1>
<%= link_to 'New Client', new_client_path %>
<table>
<tr>
<th>Name</th>
<th>Issued On</th>
<th>Notes</th>
<th>Finished?</th>
<th>Payments</th>
</tr>
<%= @clients.each do |client| %>
<tr>
<td><%= client.name %></td>
<td><%= client.date %></td>
<td><%= client.note %></td>
<td><%= client.finished %></td>
<td><%= client.payment %></td>
<td><%= link_to 'Show', client_path(client) %></td>
<td><%= link_to 'Edit', edit_client_path(client) %></td>
<td><%= link_to 'Destroy', client_path(client),
method: :delete,
data: { confirm: 'This client will be permanentally deleted, do you want to continue?' } %></td>
</tr>
<% end %>
</table>
客戶端控制器
class ClientsController < ApplicationController
def index
@clients = Client.all
end
def show
@client = Client.find(params[:id])
end
def new
@client = Client.new
end
def edit
@client = Client.find(params[:id])
end
def create
@client = Client.new(client_params)
if @client.save
redirect_to @client
else
render 'new'
end
end
def update
@client = Client.find(params[:id])
if @client.update(client_params)
redirect_to @client
else
render 'edit'
end
end
def destroy
@client = Client.find(params[id])
@client.destroy
redirect_to clients_path
end
private
def client_params
params.require(:client).permit(:name, :date, :note, :finished, :payment)
end
end
'<(%)= @ clients.each做|客戶| %>'刪除'='閱讀本文http://stackoverflow.com/a/7996827/1297435 –
謝謝我不知道何時和不使用= – Dotol