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

  • SEARCH
  • Home
  • 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 8412885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:47:26+00:00 2026-06-10T00:47:26+00:00

Arg, I’m a RoR newbie, feeling my way, and every possible reasonable combination I’ve

  • 0

Arg, I’m a RoR newbie, feeling my way, and every possible reasonable combination I’ve tried here has failed – pointers very much appreciated:

So I have items and statuses. An item has a status, referenced by status_id:

class Status < ActiveRecord::Base
  has_many :items
end

Class Item < ActiveRecord::Base
  belongs_to :status
end

A status can be something like “For Sale”, “Deleted”, “Hidden”, “Sold” etc.

On the front page of my website, I have been displaying the last 30 items added in random order:

<% latest_items = Items.last(30).shuffle %>
<% latest_items.each do |i| %>
  :
<% end %>

However I only want items displayed where the status of the item is set to display on the front page (eg only display items where the status is For Sale or Sold, but not Hidden).

I may want to add future statuses for items, so I have updated the statuses table to include a column front_page, which is set to either 1 or 0, depending on whether it is to display on the front_page or not. Multiple statuses can be displayed on the front page.

I’m struggling to work out how to reference this status.front_page field, and to build the limited array of Items. I’ve tried numerous things, and nothing is working. Am I barking up the wrong tree entirely?

If it’s of any relevance I’m using Ruby 1.9.2p320 / Rails 3.1.0.rc8

  • 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-06-10T00:47:28+00:00Added an answer on June 10, 2026 at 12:47 am

    Try using a where (conditions) statement

    Item.joins(:status).where(:statuses => {:name => ["For Sale", "Sold"]}).last(30)
    

    you could also put this into a scope

    Class Item < ActiveRecord::Base
      scope :homepage_display, joins(:status).where(:statuses => {:name => ["For Sale", "Sold"]}).last(30)
    
    # Then in your view
    Item.homepage_display
    

    I would also suggest switching around your associations, Items should not belong_to status

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Arg! I have a custom harness executable running my class library project. Every time
Here is a snippet: for arg in $@; do if [ $arg == --coverage
Here's an example: static int Main(string[] args) { foreach(string arg in args.Skip(77)) { Console.WriteLine(arg);
(function(){ pm.view.someFunction(arg) { arg is used here. } pm.view.otherFun(){ how can i pass the
Possible Duplicate: What is the difference between throw and throw with arg of caught
Arg. Inheriting projects is SO much fun. Especially when they don't work well, and
When I call perl's two-arg open() with a filename containing a trailing newline, the
Imagine the following situation: struct Args { bool arg; }; void thing(Args arg) {
I'm looking for something that works like Lisp's arg-supplied-p variables, to help differentiate a

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.