Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3852046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:15:25+00:00 2026-05-19T17:15:25+00:00

Edit: More Detailed and to the point I’m using Rails 3: I currently have

  • 0

Edit: More Detailed and to the point

I’m using Rails 3:

I currently have a list of items that are being pulled from my database and displayed on the properties/index page where people can see basic information and then click its link to go to the properties/show page. the code I’m using to call this is

<% @properties.each do |property| %>
<%= link_to property.title,  link_to_rental(property)  %>
<% end %>

The link_to_rental(property) is defined in the Properties Helper

What I’d like to do, is have a featured property on my home/index page. Is there a way to use something similar that pulls one property at random from the property controller and display its .title on the home/index page?

note: rand is deprecated in rails 3 must use random_element

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:15:26+00:00Added an answer on May 19, 2026 at 5:15 pm

    In the home controller it looks like I needed to add an array for the properties first, and then create the array to randomize the list of properties. for example:

    properties = Property.joins(:status).where(:statuses => { :available => 'Not-Rented'})
    @property = properties[rand(properties.count)]
    
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml => @properties }
      end
    

    Leaving us with this to use on the home/index view:

    <%= link_to @property.title,  link_to_rental(@property)  %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: More detailed question. I am working on batched operations in nHibernate, specifically for
Edit: I've got the solution and have described it a bit more at the
EDIT Sorry I forgot the most important part here. Each key can have more
Okay I edit my question, try to explain it more clearly: I have a
EDIT italics = more detailed explanation added to the question. Thanks. I'm building a
-- edit -- I've made the question far more detailed here: Drupal aggregators and
I created a GUI class that displays a list of items. When the user
EDIT: A bit more detailed HTML document... In short- how do I actually do
Edit: showed my exact web.config code. I have a MVC3 project that works fine
Currently I have a ListView (using the Details View). I would like to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.