我正在做一个关于议程音乐会的哈希,并在index.html.erb中在页面的最后显示了@agendas的参数。 参数显示在最后:
callback=?
我不想显示这些参数。为什么会这样?
我的文件index.html.erb是:
[#<Agenda id: 12, title: "test to show the past shows", info: "testando se aparece shows passados!", date_concert: "2015-05-13", begin_time: "2000-01-01 21:11:00", end_time: "2000-01-01 00:11:00", created_at: "2015-07-20 23:13:05", updated_at: "2015-07-20 23:13:05", user_id: nil>, #<Agenda id: 8, title: "Festival MPB Goiânia, Brasil", info: "Festival de Música Popular Brasileira em Goiânia, ...", date_concert: "2015-07-20", begin_time: "2000-01-01 00:43:00", end_time: "2000-01-01 22:40:00", created_at: "2015-07-20 22:43:17", updated_at: "2015-07-20 22:43:17", user_id: nil>, #<Agenda id: 9, title: "Mota Live Project at Disco Bataplan.", info: "Mota Live Project at Disco Bataplan. \r\nIn the Fest...", date_concert: "2015-07-20", begin_time: "2000-01-01 00:03:00", end_time: "2000-01-01 01:10:00", created_at: "2015-07-20 22:46:23", updated_at: "2015-07-20 22:46:23", user_id: nil>, #<Agenda id: 1, title: "Heineken Jazz Festival - Donostia", info: "Heineken Jazz Festival in Donostia-San Sebastian w...", date_concert: "2015-07-23", begin_time: "2000-01-01 20:30:00", end_time: "2000-01-01 00:00:00", created_at: "2015-07-19 22:06:01", updated_at: "2015-07-20 16:54:19", user_id: 3>, #<Agenda id: 13, title: "OAHspkdbasbd", info: "sdfñsdñf", date_concert: "2015-07-24", begin_time: "2000-01-01 12:27:00", end_time: "2000-01-01 14:55:00", created_at: "2015-07-21 00:28:05", updated_at: "2015-07-21 00:28:05", user_id: nil>, #<Agenda id: 10, title: "Show teste", info: "Show teste, sample!", date_concert: "2015-07-27", begin_time: "2000-01-01 23:00:00", end_time: "2000-01-01 01:00:00", created_at: "2015-07-20 22:54:23", updated_at: "2015-07-20 22:58:31", user_id: nil>, #<Agenda id: 5, title: "Show Brasil Skol Event", info: "Concert with a Event SKol Beer", date_concert: "2015-08-02", begin_time: "2000-01-01 10:40:00", end_time: "2000-01-01 13:00:00", created_at: "2015-07-20 16:56:30", updated_at: "2015-07-20 16:56:30", user_id: nil>, #<Agenda id: 2, title: "Mota Project Live - Disco Gu", info: "Concierto del grupo Mota Project Live en la Disco ...", date_concert: "2015-08-03", begin_time: "2000-01-01 21:00:00", end_time: "2000-01-01 00:00:00", created_at: "2015-07-19 23:49:56", updated_at: "2015-07-20 16:53:07", user_id: 3>, #<Agenda id: 6, title: "BBK - Bilbao Live", info: "Concierto en el BBK Live!", date_concert: "2015-08-07", begin_time: "2000-01-01 19:00:00", end_time: "2000-01-01 20:00:00", created_at: "2015-07-20 17:01:14", updated_at: "2015-07-20 17:01:14", user_id: nil>, #<Agenda id: 7, title: "Show Donosti Indie Festival", info: "Festival Indie en la ciudad de Donosti-San Sebasti...", date_concert: "2015-08-09", begin_time: "2000-01-01 22:30:00", end_time: "2000-01-01 23:40:00", created_at: "2015-07-20 22:36:11", updated_at: "2015-07-20 22:36:11", user_id: nil>]
我的agendas_controller.erb中的是:
<p id="notice"><%= notice %></p>
<div class="distance">
<div class="container">
<div class="row">
<div class="agenda_concerts">
<h1> Agenda Concerts </h1>
<hr class="featurette-divider">
<%= @agendas.each do |agenda| %>
<% if agenda.date_concert.past? %>
<% else %>
<span class="title"><%= link_to agenda.title, agenda %></span>
</br>
<span class="info"><%= agenda.info %></span>
</br>
<span class="date">Date: <%= agenda.date_concert.to_formatted_s(:rfc822) %></span>
</br>
<span class="begin_time">Begin: <%= agenda.begin_time.to_s(:time) %></span>
</br>
<span class="end_time">End: <%= agenda.end_time.to_s(:time) %></span>
</br>
<% if user_signed_in? %>
<%= link_to 'Edit', edit_agenda_path(agenda) %></td>
<%= link_to 'Destroy', agenda, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
<hr class="featurette-divider">
<% end %>
<% end %>
</div>
</div>
</div>
</div>
答案 0 :(得分:2)
您希望<% @agendas.each do |agenda| %>
代替<%= @agendas.each do |agenda| %>
<%= ... %>
和<% ... %>
都可以包含ruby语句。第一个选项将显示ruby语句返回的内容,后一个选项告诉您的视图不显示ruby代码返回的内容。调用@agendas.each
会返回议程数组,但您不想显示它,因此请使用短划线选项<% ... %>
答案 1 :(得分:2)
<%= ...... %>
您在UI中显示此代码的代码
<% ...... %>
您在此之间编写的代码不会在UI
中显示试试这个会起作用
<p id="notice"><%= notice %></p>
<div class="distance">
<div class="container">
<div class="row">
<div class="agenda_concerts">
<h1> Agenda Concerts </h1>
<hr class="featurette-divider">
<% @agendas.each do |agenda| %>
<% if agenda.date_concert.past? %>
<% else %>
<span class="title"><%= link_to agenda.title, agenda %></span>
</br>
<span class="info"><%= agenda.info %></span>
</br>
<span class="date">Date: <%= agenda.date_concert.to_formatted_s(:rfc822) %></span>
</br>
<span class="begin_time">Begin: <%= agenda.begin_time.to_s(:time) %></span>
</br>
<span class="end_time">End: <%= agenda.end_time.to_s(:time) %></span>
</br>
<% if user_signed_in? %>
<%= link_to 'Edit', edit_agenda_path(agenda) %></td>
<%= link_to 'Destroy', agenda, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
<hr class="featurette-divider">
<% end %>
<% end %>
</div>
</div>
</div>
</div>
希望它可以帮到你