views:

48

answers:

2

Hi, I have built a small text based search engine on ROR which will display relevant records having a specified search word in it.since few of the records has more than 1000 words i have truncated each result set to 200 characters.My views file search.html.erb looks like this

 <% @results_with_ranks.each do |result| -%>

  <% content_id = rtable.find(result[0]).content_id %>
  <% content= Content.find(content_id) %>
  <%= truncate content.body, :length => 200 %><br/>

 <p> Record id <%= content.id %></p>

  <hr style="color:blue"> 

  <% end -%>

I want to provide an option so that whenever any truncated record is selected its entire body has to be displayed. I also want to paginate the result page displaying some fixed number of records per page.Can any body help me in doing this? Thanks in advance.

+1  A: 

For pagination you have no better choice than http://wiki.github.com/mislav/will_paginate/.

I am not sure exactly what you mean by when the record is selected, but it appears like a Javascript toggle() (if using jquery http://api.jquery.com/toggle/).

Documentation on how to use both these features is very complete

Peer

Peer Allan
This would have been my answer provided the information from kshama.. will_paginate is a great tool!
Rabbott
A: 

I'd approach this problem one of two ways.

  1. Load the full text of a result and hide any extraneous text using CSS/javascript.
  2. Only load the first 200 words, as you're doing now, and load the full text on a specific action from the user (in this case, probably on hover or click).

Option 1 is simpler, but option 2 would save you a fair amount of bandwidth/page load time.

Recommended starting points:

  1. http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html
  2. http://guides.rubyonrails.org/layouts_and_rendering.html

Shouldn't be too hard to figure out once you've got a handle of how rendering works in rails and implement those javascript helpers into your application.

Damien Wilson