I’m trying to take advantage of partials to display a random
testimonial a few pages and I think my newness is getting in the way
here, I’m hoping someone can offer some assistance.
In my controller I have:
def index
@title = “Testimonials”
@testimonials = Testimonial.find(:all)
end
def random
@testimonials = Testimonial.find(:first, :order => ‘RAND()’)
end
Now I have a partial for random, but how would I get it to call the
random method? The display is similar to the all display of (without
the loop):
<% if @testimonials.blank? -%>
There are currently no testimonials.
<% else -%><% end -%><%= testimonial.comment %>
<%= testimonial.cite -%><% if not testimonial.company.blank? %>, <%= testimonial.company -%><% end -%>
Lastly as well, being that the full list and the random code is so
similar minus the loop - is there a way I can make this a little more
DRY by having it in the same partial somehow?
Thanks a lot everyone,
Blaine