Nov 8, 2006

RubyOnRails pagination fix

update: Rails Pagination is ugly and will be deprecated.

Here's a fix I made to get around a problem in Rails Pagination.


# pagination links do not support all form objects properly
# a hash with values such as date[year], date[month] and date[day]
# will be included in the pagination link as date=month11day9year2006
#
# putting this function in application_helper.rb and calling it from your
# view will properly construct the pagination links to include your form
# input
#
# <%= pagination_links(@cdr_pages, :params => marshall_objects(params)) %>
#
def marshall_objects(params)
params.each do |key, val|
if val.class == HashWithIndifferentAccess
params[key] = nil
val.each {|sub_key, sub_val| params[key + '[' + sub_key + ']'] = sub_val}
end
end
params
end

No comments: