I put everything in a pastie to make it a bit more readable: http://pastie.org/593379 This is the gist: Will_paginate doesn''t play quite nice. The first result set is fine, and when I click on one of the paginated links, it returns the following error: Couldn''t find DictatedExam with ID=filter_widget observe_field triggers filter_widget which calls the paginated search.. Which is then rendered in a partial. Why do things simple when you can do it complicated, right ? -- Posted via http://www.ruby-forum.com/.
Addendum: This is what the links look like. I have no idea what they''re -supposed- to look like. http://localhost:3000/dictated_exams/filter_widget?page=4 -- Posted via http://www.ruby-forum.com/.
Aldric Giacomoni wrote:> Addendum: > > This is what the links look like. > I have no idea what they''re -supposed- to look like. > > http://localhost:3000/dictated_exams/filter_widget?page=4Okay.. I figured this bit out: Processing DictatedExamsController#show (for 127.0.0.1 t 2009-08-24 14:54:09) [GET] Parameters: {"id"=>"filter_widget", "page"=>"2"} DictatedExm Load (15.0ms) SELECT * FROM "dictated_exms" WHERE ("dictated_exms"."id" = 0) ActiveRecord::RecordNotFound (Couldn''t find DictatedExam with ID=filter_widget): pp/controllers/dictated_exams_controller.rb:16:in `show'' So I''m giving the id of ''filter_widget''.. Why ? -- Posted via http://www.ruby-forum.com/.
Okay! I got the pagination links to work. Now I need them to display in the same div where the first results go, without reloading a page and discarding my layout. I had to: ROUTES.RB map.resources :dictated_exams, :collection => {:filter_widget => :get} _list.erb: <%= will_paginate dictated_exams, :params => {:date => date} %> index.html.erb, the observe_field: :url => {:action => ''filter_widget'', :controller => ''dictated_exams'', :method => :post }, dictated_exams_controller.rb: def filter_widget @date ||= params[:date].to_date end_date = @date + 1.days dictated_exams = DictatedExam.search_one_day(@date, params[:page]) render :partial => ''dictated_exams/list'' , :locals => { :dictated_exams => dictated_exams, :date => @date } end Now to get the results to display where I want them to display... -- Posted via http://www.ruby-forum.com/.
AND FIXED! I followed http://jellofishi.com/blog/?cat=3 I created app/helpers/remote_link_renderer.rb class RemoteLinkRenderer < WillPaginate::LinkRenderer def prepare(collection, options, template) @remote = options.delete(:remote) || {} super end protected def page_link(page, text, attributes = {}) @template.link_to_remote(text, {:url => url_for(page), :method => :post}.merge(@remote)) end end And then in the environment.rb I added, after the Initializer block: require "will_paginate" WillPaginate::ViewHelpers.pagination_options[:renderer] = ''RemoteLinkRenderer'' My will_paginate has become: <%= will_paginate dictated_exams, :params => {:date => date }, :remote => { :update => ''filter_counts''} %> And now it all works.. -- Posted via http://www.ruby-forum.com/.