好的,这就是我拥有显示所有建筑物的视图商店的东西。我只想向我展示状态为“待售”的建筑物
在意见商店我有:
<% 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 %>
在控制器>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
有没有用 IF 语句来做?还是我必须改变<% @buildings.each do |building| %>
?