Hi all,
Here’s my general setup on the specific template I’m having issues with:
will_paginate for pagination
custom methods for sorting
1-form for team search
1-form for search by date
When searching for a team for instance, the url returned will be:
/rushing_offenses?search=Florida
When searching by date, the url returned will be:
/rushing_offenses?compiled_on=2009-07-02
Pagination has a show all button:
/rushing_offenses?numteams=120&orderby=rank&sortby=asc
Pagination has a show simple button:
/rushing_offenses?orderby=rank&sortby=asc
If I click on each page number within will paginate the URL changes to:
/rushing_offenses?compiled_on=2009-07-02&orderby=rank&page=2&sortby=asc
My table helper functions for sorting and for the show all / show simple
are:
adds up / down images for asc and desc sorting to all table columns
based on controller name called
def sort_column(title, direction)
direction == “asc” ? image = “up.gif” : image = “down.gif”
(link_to image_tag(image, :border=>0, :alt => direction),
:controller => controller.controller_name, :numteams => (@showall ? 120
: nil), :orderby => title, :sortby => direction) if !@searchteams
end
adds a button to show all teams on tables based on controller name
called.
def show_all_teams
(link_to “Show All Teams”, :controller =>
controller.controller_name, :numteams => 120, :orderby => ‘rank’,
:sortby => ‘asc’) if !@showall
end
adds a button to show simplified views on tables based on controller
ame called…
def show_simple_view
(link_to “Show Simple View”, :controller =>
controller.controller_name, :numteams => nil, :orderby => ‘rank’,
:sortby => ‘asc’) if @showall || @searchteams
end
The main call to the list function in my index is done through the
following controller call:
list(params[:search], params[:page], params[:orderby], params[:sortby],
params[:numteams], params[:compiled_on])
Which is sent to the model:
def self.list(search, page, orderby, sortby, numteams, datevar)
# convert datevar to today’s date if it’s empty/nil/or not formatted
properly due to form_tag lacking model validation checks
datevar = todaysdate if datevar.empty? || datevar.nil? ||
DATE_VALIDATE_REG.match(datevar).nil?
# we need to convert datevar to time and find the beginning of that
week for scope comparison
convert_time = datevar.to_time.beginning_of_week
# we need to reconvert the time back to a readable week start date
week_start_date = convert_time.to_date.strftime(’%Y-%m-%d’)
# using our named scope to checked for compiled_on which is a date
type column to search within specified date ranges
named_scope :compiled_on_week, lambda { { :conditions =>
[‘compiled_on >= ? and compiled_on <= ?’, week_start_date, datevar] } }
# automatically ordering by rank if our orderby is nil or empty
orderby = “rank” if orderby.nil? || orderby.empty?
# deciding whether to sort by ascending or descending
orderall = (sortby != ‘asc’ && sortby != nil) ? “DESC” : “ASC”
# calling our named_scope along with will_paginate to pull our data
compiled_on_week.paginate :joins => :team, :conditions => [‘name
like ?’, “%#{search}%”], :order => orderby + " #{orderall}", :per_page
=> numteams, :page => page
end
=======================================================
Okay, sorry for the long setup before getting to my question(s). I just
wanted to be certain that I provided as much information as I could
about the issue.
What I want is to have all the params merged into one long URL to look
like so:
/rushing_offenses?search=Florida&?compiled_on=2009-07-02&?numteams=120&orderby=rank&page=2&sortby=asc
I know that I need to use params.merge for this but I’m not sure how to
go about doing it with the different parts on my page as well as with
some of the helper models I defined above.
What advice/suggestions can you give me?
Many great thanks in advance!