Maarten van den Ende
2006-Aug-01 21:42 UTC
[Rails] paginate, search, sort with ajax problem
hello I hope somebody can help me figure this out. found this great tutorial at http://dev.nozav.org/rails_ajax_table.html. got it working except for one thing. I can''t seem to make the pagination work. The link_to_remote defined in the helper is pointing to the wrong url. I have set up things like so: defined a search method in de project_controller located in apps/admin/project. In de tutorial the method is called list. defined in the item_controller I copy and paste the helper methodes to project_helper in the folder helpers/admin/project_helper The files that create the view are located in views/admin/project Problem is that the helper method pagination_links_remote and sort_link_helper crate a link like the folowing: http://localhost:3001/admin/admin/project/search?query=we&sort=name where is should look like this to make the pagination work: http://localhost:3001/admin/project/search?query=we&sort=name notice the diference near "admin", printed only once. I think I have to ajust the helper methods but I don''t know how, please help -- Posted via http://www.ruby-forum.com/.
Post your helper code. Max
Maarten van den Ende
2006-Aug-01 22:49 UTC
[Rails] Re: paginate, search, sort with ajax problem
Max Muermann wrote:> Post your helper code. >my project_helper code for module Admin module Admin::ProjectHelper #method used in search form results def sort_td_class_helper(param) result = ''class="sortup"'' if @params[:sort] == param result = ''class="sortdown"'' if @params[:sort] == param + "_reverse" return result end #method used in search form def pagination_links_remote(paginator) page_options = {:window_size => 2} pagination_links_each(paginator, page_options) do |n| options = { :url => {:action => ''search'', :params => @params.merge({:page => n})}, :update => ''search_table'', :before => "Element.show(''spinner'')", :success => "Element.hide(''spinner'')" } html_options = {:href => url_for(:action => ''search'', :params => @params.merge({:page => n}))} link_to_remote(n.to_s, options, html_options) end end #method used in search form results def sort_link_helper(text, param) key = param key += "_reverse" if @params[:sort] == param options = { :url => {:action => ''search'', :params => @params.merge({:sort => key, :page => nil})}, :update => ''search_table'', :before => "Element.show(''spinner'')", :success => "Element.hide(''spinner'')" } html_options = { :title => "Sort", :href => url_for(:action => ''search'', :params => @params.merge({:sort => key, :page => nil})) } link_to_remote(text, options, html_options) end end -- Posted via http://www.ruby-forum.com/.
Maarten van den Ende
2006-Aug-02 07:40 UTC
[Rails] Re: paginate, search, sort with ajax problem
the view: <% if @total == 0 %> <p>Nothing found...</p> <% else %> <p>Number of results: <b><%= @total %></b></p> <p> <% if @user_pages.page_count > 1 %> Page : <%= pagination_links_remote @user_pages %> <% end %> </p> <table> <thead> <tr> <td <%= sort_td_class_helper "Name" %>> <%= sort_link_helper "Name", "name" %> </td> <td <%= sort_td_class_helper "email" %>> <%= sort_link_helper "Email", "email" %> </td> <td <%= sort_td_class_helper "user_name" %>> <%= sort_link_helper "Username", "user_name" %> </td> </tr> </thead> <tbody> <% @user.each do |u| %> <tr class="<%= cycle("even","odd") %>"> <td><%= u.name %></td> <td><%= u.email %></td> <td><%= u.user_name %></td> </tr> <% end %> </tbody> </table> <% end %> -- Posted via http://www.ruby-forum.com/.