Ruby on Rails 3。每个问题 [英] Ruby on Rails 3 .each do Problem
问题描述
我对Ruby on Rails有些不熟悉,并且一直在学习,但似乎遇到了一个我似乎无法解决的问题。
<运行Rails 3.0.9& Ruby 1.9.2
我在View中运行以下语句:
<%= @ events.each do | f | %GT;
<%= f.name%><%= link_toView,event_path(f)%>< br />< hr />
<%end%>
以下是我的控制器:
class AdminController< ApplicationController
def flyers
@events = Event.all
end
end
这会遍历每个记录并输出适当的名称,但问题是最后它会显示所有记录的所有信息,如下所示:
'pre>
[#<使用者ID:1,用户名: 测试帐户,电子邮件地址: test@gmail.com,password_hash:$ 2A $ 10 $ Rxwgy。 0ZEOb0lMGEIliPBeB / jPSp8roeKdbMvXcLi32R ...,password_salt:$ 2a $ 10 $ Rxwgy.0ZEOb0lMGEIliPBe,created_at:2111359287.2303703,updated_at:2111359287.2303703,isadmin:true>]
我对这个网站很陌生,所以我不确定你是否需要更多的细节,但是任何帮助都会被赞赏,毕竟我还在学习。 >
在此先感谢。
您应该使用<$ c $对于 .each
行来说,c><%,而不是<%=
因此
<%= @eve nts.each do | f | %GT;
应该是
<%@ events.each do | f | %GT;
I'm sort of new to Ruby on Rails and have been learning just fine, but have seem to run into a problem that I can't seem to solve.
Running Rails 3.0.9 & Ruby 1.9.2
I'm running the following statement in my View:
<%= @events.each do |f| %>
<%= f.name %><%= link_to "View", event_path(f) %><br/><hr/>
<% end %>
And this in my controller:
class AdminController < ApplicationController
def flyers
@events = Event.all
end
end
This goes through each of the records and outputs the appropriate name, but the problem is that at the end it displays all of the information for all of the records like so:
[#<User id: 1, username: "test account", email: "test@gmail.com", password_hash: "$2a$10$Rxwgy.0ZEOb0lMGEIliPBeB/jPSp8roeKdbMvXcLi32R...", password_salt: "$2a$10$Rxwgy.0ZEOb0lMGEIliPBe", created_at: 2111359287.2303703, updated_at: 2111359287.2303703, isadmin: true>]
I'm new to this site, so I'm not sure if you need any more details, but any help is appreciated, after all, I'm still learning.
Thanks in advance.
You should be using <%
, not <%=
for your .each
line, so
<%= @events.each do |f| %>
should be
<% @events.each do |f| %>
这篇关于Ruby on Rails 3。每个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!