2015-07-21 57 views
1

我正在做一個議程音樂會的散列表,並在index.html.erb頁面的最後顯示了@agendas的參數。 參數顯示在最後:爲什麼它在頁面的最後顯示參數?

[#<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>] 

enter image description here

我不想顯示參數。爲什麼發生這種情況

我的文件index.html.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> 

在我agendas_controller.erb是:

def index 
    @agendas = Agenda.all 
end 

回答

2

你想<% @agendas.each do |agenda| %>代替<%= @agendas.each do |agenda| %>

<%= ... %><% ... %>可以同時包含紅寶石聲明。第一個選項將顯示ruby語句返回的內容,而後一個選項讓您的視圖不顯示ruby代碼返回的內容。調用@agendas.each返回議程數組,但你不想顯示它,所以使用破折號選項<% ... %>

+0

謝謝你們spejamchr和santos爸爸這對我有用! – rld

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> 

希望它可以幫助你

相關問題