# Baffled on forms and controllers!

**URL:** <https://www.ruby-forum.com/t/baffled-on-forms-and-controllers/164144>\
**Category:** Rails\
**Created:** [March 28, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/baffled-on-forms-and-controllers/164144 "2009-03-28T17:53:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [March 28, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/baffled-on-forms-and-controllers/164144/1 "2009-03-28T17:53:35Z")

</div>

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) }  
end

end

and in my controller…

@date\_filter = DateFilter.new(params[: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  
admin/articles/index.html.erb:  
21:

### Filter by: Date
  
22: Between   
  
23:  
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

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [March 28, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/baffled-on-forms-and-controllers/164144/2 "2009-03-28T18:19:17Z")

</div>

dont worry. fixed. replaced form\_for with form\_tag
