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

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.
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-03-28 17: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) }
 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:     <h3>Filter by: Date</h3>
22:     Between <br/>
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
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-03-28 18:19

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