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
nithya nithya wrote:> 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
>
>