I have a total of 30 Project thumbnails that I'm planning to render in
groups of 8 in my index page. I'm going to put a "next" button that
will replace the present group with the next 8 thumbnails, and so on
until one gets to the final group of thumbnails. My codes are working
but only for the first two groups: the first group is rendered when
one loads the index page, the 2nd group when one presses the "next"
button. Pressing the "next" button further doesn't change anything,
the 2nd group isn't replaced by anything. Anyway, I used AJAX and
partials to do this and here are my codes:
In the index view:
<%= render(:partial => "thumbnail", :collection => @newthumbs) %>
<% form_remote_tag :url => {:action => "next", :remaining =>
@everything} do %> #next button
<%= submit_tag "Next" %>
<% end %>
In the next.js.rjs:
page.replace_html("thumbnail" , :partial => "thumbnail" , :collection
=> @newthumbs)
In the _thumbnail.html.erb partial:
<%= image_tag thumbnail.image %> #just to output a project's image
In the Controller:
def index
@everything = Project.find(:all).reverse #since I want to
render the newest projects first
@newthumbs = [] #collection that partial _thumbnail.html.erb will
replace with
for project in @everything do
if @newthumbs.size < 8 #inputs 8 objects for the first group
@newthumbs << project
end
end
@remaining = @everything - @newthumbs #sets the remaining
thumbnails to be rendered
end
def next
@newthumbs = []
@everything = []
for remain_id in params[:remaining] do
project = Project.find(remain_id)
if @newthumbs.size < 8
@newthumbs << project
else
@everything << project
end
end
@remaining = @everything - @newthumbs # sets a new array for the
remaining thumbnails
respond_to do |format| #AJAX
format.js if request.xhr?
format.html {redirect_to_index}
end
end
My guess is that the app is only reading @newthumbs and @remaining
arrays within the "index" method. It doesn't take into account the
updates that were made to the arrays within the "next" method. How do
I fix this?
Thank you very much in advance!
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.