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

Post your helper code.

Max

Max M. 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

the view:

<% if @total == 0 %>

Nothing found...

<% else %>

Number of results: <%= @total %>

<% if @user_pages.page_count > 1 %>
Page :
<%= pagination_links_remote @user_pages %>
<% end %>

<% @user.each do |u| %>
<tr class="<%= cycle(“even”,“odd”) %>">





<% end %>
> <%= sort_link_helper "Name", "name" %> > <%= sort_link_helper "Email", "email" %> > <%= sort_link_helper "Username", "user_name" %>
<%= u.name %> <%= u.email %> <%= u.user_name %>

<% end %>

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