2 ajax related questions


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.

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

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 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