Helper in controller?


I have have written a statictics controller for one of my applications -
and I want to allow users to pull out certain statistics from a certain

In my view, I’ve added something like this:

<%= form_tag :action => “bu” %>


From: <%= select_date(date =, :prefix => ‘from’) %>

To:<%= select_date(date =, :prefix => ‘to’) %>
<%= submit_tag ‘BU stat’ %>

<%= end_form_tag %>

Now, to be able to build the select query in my controller, I’ve done
like this:
from = params[:from][:year] + ‘-’ + params[:from][:month] + ‘-’ +
to = params[:to][:year] + ‘-’ + params[:to][:month] + ‘-’ +
@lines = Line.find(:all, :conditions => ["projects.bu like ? and
(projects.created_at BETWEEN ? AND ?) ", “#{@params[:bu]}%”,
from.to_date, to.to_date], :include => [:project]

It all works, but it is not pretty. I wanted to hear if anybody would
have a suggestion of how to do this the right way ?
If this is the only way, I’d also like to hear if it is possible to
write a helper (for the controller) to the from and to variables from
all the params[] so I do not have to create these lines for each action
that requires from- and to-dates.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs