How to give conditions in rails


#1

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”) %>

<%= link_to 'Add holiday', :action => 'holiday_edit' %>


List of Holidays


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

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

<% for holiday in @holidays d11=h(holiday.holiday_date) d111=d11.split('-') puts(d111[0]) %> <% end %>
Date Description Actions
<%= h(holiday.holiday_date) %> <%= h(holiday.description) %> <%= 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}'?" %>

<% end %> <% if @holidays.length > 0 %> <% end %>
<%= link_to 'Add holidays', :action => 'holiday_edit' %>
<%= 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 removed_email_address@domain.invalid

thanks

regards
Nithya


#2

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