Need help to format the result page after searching
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) %&开发者_Go百科gt;
<%= 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.
For pagination you have no better choice than https://github.com/mislav/will_paginate/wiki
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
I'd approach this problem one of two ways.
- Load the full text of a result and hide any extraneous text using CSS/javascript.
- 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:
- http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html
- 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.
精彩评论