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 8663713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:03:15+00:00 2026-06-12T17:03:15+00:00

ok here is the thing i have the view store that shows all the

  • 0

ok here is the thing i have the view store that shows all the buildings. all i want to do is to show me only the buildings with the status “for sale”

in views store i have:

<% if notice%>
<p id="notice"> <%= notice%></p>
<%end%>

<h1>All Priorities</h1>

 <%= form_tag  store_path, :method => 'get'  do %>
<p>
  <%=text_field_tag :search , params[:search]%>
  <%= submit_tag "Search", :name=> nil%>
  </p>
  <%end%>

<% if @buildings.present? %> 
 <% @buildings.each do |building| %> 
<div class="entry">
    <div class="img">
    <%= image_tag (building.photo.url)%></div>
    <div class=" disc">
    <h3>Name of the Bulding:  <%= building.title %></h3>
     <h4>Status: <%= building.status %></h4>
    Info: <%=sanitize(building.description)%>
    <div class="price_line">
        <span class="price">Price: <%= sprintf("€ %0.02f",building.price)%></span><br/>
        <div class="button">
        <%= button_to("I want to see it", {:controller => "seeits", :action => "new", :building_id => building.id})%></div>

    </div> 

    <div class="pages">
    <%= will_paginate @buildings %></p>
    </div>

    </div>
<% end %>

</div>

<% else %> does not much try another name<% end %>

in controller>buildings_controller

 def index 

    @buildings = Building.all

      respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @buildings }
    end

  end


  # GET /buildings/1
  # GET /buildings/1.json
  def show
    @building = Building.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @building }
    end
  end

is there to do it with IF statement ? or i have to change <% @buildings.each do |building| %> ?

  • 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-12T17:03:16+00:00Added an answer on June 12, 2026 at 5:03 pm

    The simplest way to filter your list of buildings would be to filter it in your view:

    @buildings.select{|b| b.status == "for sale"}.each do |building|
    

    However, this still requires you to query the DB for all your items – which is inefficient. Your views should be as simple as possible, and this isn’t the DRY Rails way to do things.

    A more robust way would be to use a where clause in your controller:

    @buildings = Building.where("status = 'for sale'")
    

    However, this still puts too much logic in your controller. Your model should be able to handle all of the query logic for you. The best way would be to create a Rails scope on your Building model:

    class Building < ActiveRecord::Base
      ...
      scope :for_sale, where(:status => "for sale")
      ...
    end
    

    Then, in your controllers (or views) you would only have to do:

    @buildings = Building.for_sale
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some doubt on wget command. Here is the thing I want to
Here is the thing. I currently have a tabBar controller, with several navigation controllers
Here's the thing. I have an interface, and I would to put the Include
Here is the thing. Right now I have this e-commerce web site where people
I have a problem with docking. Here is the thing. I hope I can
CSS newbie here. Strange thing is happening, I have gaps between links, and I
I have a problem with an MVC view that I just cannot seem to
I have three camera-based apps (that take still pictures) in the app-store and have
Here is the problem. I have a stored procedure that transforms normalized data into
I have a nice little app on the app store that does pretty well

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.