Forum: Ruby on Rails How to give conditions in rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0d1dc788e7b7abe4dd0a911d47d3b2a5?d=identicon&s=25 Nithya N. (nithyak)
on 2006-06-13 08:02
Hi, I have Holiday table. the fileds are id,holiday_date,description. i
added new records and list them also. when i listed all the records in
the database are listed but i want to list only one particular year
records. my holiday_list.rhtml page is as follows

<%= stylesheet_link_tag "common", :media => "all" %>
<%= error_messages_for 'holiday' %>
<%= form_tag(:controller => "admin", :action => "holiday_list") %>

<table align="center" width="50%" cellpadding="5" cellspacing="3">
  <tr>
    <td colspan="2">
      <center><b>
      <%= link_to 'Add holiday', :action => 'holiday_edit' %>
</center></b>
    </td>
  </tr>
</table>
<br>
<br>
<p>
  <h1 align="center"><i>List of Holidays</i></h1>
</p>

<br>

<%
  if @holidays.length > 0
%>
<%
    d=select_year(2006,:prefix => "year",:discard_type => true)
%>

<p align="right"><%=d%><%= submit_tag("Ok", :id => 'form-submit-button')
%></p>

<table cellpadding="5" cellspacing="0" border="3" align="center"
width="50%" bordercolor="green">
  <tr valign="top"
><th>Date</th><th>Description</th><th>Actions</th></tr>
		     <%
		       for holiday in @holidays
		       d11=h(holiday.holiday_date)
		       d111=d11.split('-')
		       puts(d111[0])
     %>
  <tr>
     <td width="20%"><b> <%= h(holiday.holiday_date) %></b></td>
     <td width="50%"><b> <%= h(holiday.description) %></b></td>
     <td class="ListActions">
        <%= link_to 'Show', :action => 'holiday_show', :id => holiday %>
        <%= link_to 'Edit', :action => 'holiday_edit', :id => holiday %>
    	    <%= link_to 'Destroy', { :action => 'holiday_destroy', :id =>
holiday },
                             	    :confirm => "Are you sure to delete
holiday '#{holiday.description}'?" %>
     </td>
  </tr>
  <% end %>
  </tr>
</table>
<br>
<%
  end
%>
<table align="center" width="50%" cellpadding="5" cellspacing="3">
  <%
    if @holidays.length > 0
  %>
  <tr>
    <td colspan="2">
      <center><b>
      <%= link_to 'Add holidays', :action => 'holiday_edit' %>
</center></b>
    </td>
  </tr>
  <%
    end
  %>
</table>
<%= end_form_tag %>

in admn_controller.rb file inclues


 def holiday_list
    @holiday_pages, @holidays = paginate :holidays
  end

it displays all the records.

can anybody mail how to display only particular year records.

if u have any idea about this kindly mail me nithya2k4@hotmail.com

thanks

regards
Nithya
Jason Roelofs (Guest)
on 2006-06-13 13:50
(Received via mailing list)
I'd say your best bet is to do the filtering in the controller, so that
@holidays only contains the records you want to show, besides the fact
that it's easier to do there than in the view.

Jason
This topic is locked and can not be replied to.