Forum: Ruby on Rails baffled on forms and controllers!!

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave S. (Guest)
on 2009-03-28 18:53
Hi Chaps,

Having a little issue with my date filter business here, ive got a
date_filter (something i added to my form builder - which works by the
way) in my page, and I want to use it to filter my @articles.

in my page.....

<% form_for @date_filter do |f| %>
    <%= f.date_field :before %>
    <%= f.date_field :after %>
<% end %>

in my ruby class...

class DateFilter
 attr_accessor :before, :after

 def initialize(attributes)
    attributes.each { |k,v| self.send("#{k}=", v) }


and in my controller...

  @date_filter =[:date_filter])
    @articles = @results.find(:all,
                                :conditions => [ "created_at >= ? and
created_at <=?", @filter.before, @filter.after],
                                :order => 'created_at desc', :page =>
{:size => 5, :current => params[:page]})

but I am receiving the following error...

ActionView::TemplateError (Called id for nil, which would mistakenly be
4 -- if you really wanted the id of nil, use object_id) on line #24 of
21:     <h3>Filter by: Date</h3>
22:     Between <br/>
24:     <% form_for @date_filter do |f| %>
25:         <%= f.date_field :before %>
26:         <%= f.date_field :after %>
27:     <% end %>

Perhaps someone could help me to see whats going wrong...

Many thanks in advance
Dave S. (Guest)
on 2009-03-28 19:19

dont worry. fixed. replaced form_for with form_tag
This topic is locked and can not be replied to.