Forum: Ruby on Rails 2 ajax related questions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Szymon N. (Guest)
on 2006-03-29 11:41
Hi!

I've got list of project on the main page and some content. If user
clicks on one of the project i use ajax to update div with content with
project data. I'm displaying only one project at a time.

In index action i just collect all projects:
@projects = Project.find(:all, :order => "date DESC")

In show action i render project partial:
render :partial => "project", :locals => {:project =>
Project.find(params[:id])} if params[:id]


How to create "next/previous project" links using ajax? I've looked at
"How to paginate with ajax", but i can't make it work.

Is it possible to somehow wait for images to be loaded and show updated
element afterwards? Now :complete event triggers, when all html data is
received, but browser still downloads images from the server.
Szymon N. (Guest)
on 2006-03-30 14:57
I tried to use paginate in my controller:

@project_pages, @project = paginate :projects, :conditions => ["id = ?",
params[:id]], :per_page => 1
render :partial => "project", :locals => {:project => @project.first,
:project_pages => @project_pages}


But links in the partial are not displayed:

<%= link_to "Previous page", { :page => @project_pages.current.previous
} if @project_pages.current.previous %>
<%= link_to "Next page", { :page => @project_pages.current.next } if
@project_pages.current.next %>


If :conditions in paginate method is used not for finding current
element, but for filtering elements from the set to be used for
paginator, then it would explain why previous/next links are not
displayed.

But if it's true, then how get specified (by params[:id]) element and
use paginate to display previous/next links to proper elements?
This topic is locked and can not be replied to.