I''m using a web service to retrieve an array of results to a search and a render :partial to display those results to the user, while at the same time putting the results into the session. Is there a way for my _book.rhtml file to have access to the index of the result currently being displayed, like each_with_index makes available to its block? This would allow me to have the client pass back the index and pull the data from the session, thus assuring that the client hasn''t fooled with it. Thanks for any ideas! Sean ----- Sean McMains AIM: SeanMcTex http://www.mcmains.net/ruminations -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060102/ef8c3d7e/attachment.html
> Is there a way for my _book.rhtml file to have access to the index > of the result currently being displayed, like each_with_index makes > available to its block? This would allow me to have the client pass > back the index and pull the data from the session, thus assuring > that the client hasn''t fooled with it.Instead of using the :collection parameter to render, render your partial from inside an each_with_index, and pass in the index as a parameter to the partial using :locals. AC::Base#render: http://api.rubyonrails.com/classes/ActionController/ Base.html#M000178 -Ben
Sean McMains wrote:> I''m using a web service to retrieve an array of results to a search and > a render :partial to display those results to the user, while at the > same time putting the results into the session. Is there a way for my > _book.rhtml file to have access to the index of the result currently > being displayed, like each_with_index makes available to its block? This > would allow me to have the client pass back the index and pull the data > from the session, thus assuring that the client hasn''t fooled with it.Your _book.rhtml partial will be able to access the index in the local variable book_counter. This counts from zero. This doesn''t seem to be covered in the RDoc for render, but it is covered in the Agile Web Development book (in the section titled "Partials and Collections", page 361 in my PDF.) regards Justin
Reasonably Related Threads
- Re: Getting Index When Using render :partial (Benjamin Stiglitz)
- HTML Fragment not Loading in Firefox; Fine Elsewhere
- Using SQL to get a whole record when using aggregate functions
- State of the Art in Login?
- What is difference between render & redirect methods?