I'm creating a search form to retrieve publishers created_at between
start_date and end_date.
<%= simple_form_for @publisher_criteria, :url =>
publisher_reports_path, :html => {:method => :get} do |f| %>
<%= f.input :start_date, :as => :date, :include_blank => true %>
<%= f.input :end_date, :as => :date, :include_blank => true %>
<%= f.submit :value => t("commons.search"), :class => "btn" %>
<% end %>
It doesn't work in this way, because Publisher model hasn't start_date
and end_date attributes. I tried to create to create a simple classe
class PublisherCriteria
attr_accessor :start_date
attr_accessor: end_date
end
But it seems that simple_form needs an ActiveRecord Model to bind
properly.
I used a dirty workaround to solve it
(@publisher_criteria instance of Publisher < ActiveRecord::Base)
<%= simple_form_for @publisher_criteria, :url =>
publisher_reports_path, :html => {:method => :get} do |f| %>
<%= f.input :created_at, :as => :date, :include_blank => true %>
<%= f.input :updated_at, :as => :date, :include_blank => true %>
<%= f.submit :value => t("commons.search"), :class => "btn" %>
<% end %>
in the controller
criteria = ["created_at >= ? and created_at <= ?",
@publisher_criteria.created_at, @publisher_criteria.updated_at]
@publishers = @partner.publishers.where(criteria).all
What is the best approach to do it with simple_form/rails
architecture?
Cheers,
Pablo Cantero