0
而不是顯示鏈接到每個對象的節目路徑在我的索引頁的表格,我想有每個對象的引導模式在那裏,它將使展會在模態內查看。當我點擊的模式,它顯示的模式,而不是對象的顯示視圖中的整個application.html.erb模板。有沒有辦法只顯示對象的節目來看,雖然仍停留在索引頁上,而不是產生整個應用程序模板。的Rails要顯示一個模式內的對象#顯示,而無需加載應用程序模板
index.html.erb
<p id="notice"><%= notice %></p>
<h1>Buildings</h1>
<table class="table table-striped">
<thead>
<tr>
<th>County</th>
...
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @buildings.each do |building| %>
<tr>
<td><%= link_to 'Show', building %></td>
<td><%= link_to 'Edit', edit_building_path(building) %></td>
<td><%= link_to 'Destroy', building, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<div class="text-center">
<%= link_to "#{building.development_name}", building, class: 'btn btn-primary', data: {toggle:'modal', target: '#myModal'} %>
</div>
</tbody>
</table>
<br>
<div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content animated bounceInRight">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<i class="fa fa-laptop modal-icon"></i>
<h4 class="modal-title"><%= building.development_name %></h4>
<small class="font-bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</small>
</div>
<div class="modal-body">
...
<div class="form-group"><label>Sample Input</label> <input type="email" placeholder="Enter your email" class="form-control"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<% end %>
buildings_controller.rb
class BuildingsController < ApplicationController
before_action :set_building, only: [:show, :edit, :update, :destroy]
# GET /buildings
# GET /buildings.json
def index
@buildings = Building.where(user_id: current_user)
end
# GET /buildings/1
# GET /buildings/1.json
def show
end
# GET /buildings/new
def new
@building = Building.new
end
# GET /buildings/1/edit
def edit
end
# POST /buildings
# POST /buildings.json
def create
@building = Building.new(building_params)
respond_to do |format|
if @building.save
session[:building_id] = @building.id
redirect_to listing_wizards_path
format.html { redirect_to @building, notice: 'Building was successfully created.' }
format.json { render :show, status: :created, location: @building }
else
format.html { render :new }
format.json { render json: @building.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /buildings/1
# PATCH/PUT /buildings/1.json
def update
respond_to do |format|
if @building.update(building_params)
format.html { redirect_to @building, notice: 'Building was successfully updated.' }
format.json { render :show, status: :ok, location: @building }
else
format.html { render :edit }
format.json { render json: @building.errors, status: :unprocessable_entity }
end
end
end
# DELETE /buildings/1
# DELETE /buildings/1.json
def destroy
@building.destroy
respond_to do |format|
format.html { redirect_to buildings_url, notice: 'Building was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_building
@building = Building.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def building_params
params.require(:building).permit(:list_type, :county, :area, :city, :folio, :street, :compass_point, :street_name, :state, :zip, :zip4, :unit, :legal, :zoning, :geographical, :municip_code, :township, :section, :subdivision, :parcel, :map_coordinates, :elementary_school, :middle_school, :senior_high_school, :subdivision_name, :development_name, :model_name_in_mls, :user_id, additional_room_ids: [], amenity_ids: [], approval_ids: [], construction_ids: [], cooling_description_ids: [], design_ids: [], dining_area_ids: [], equipment_ids: [], exterior_feature_ids: [], floor_ids: [], heat_ids: [], interior_feature_ids: [], leasing_term_ids: [], lot_description_ids: [], misc_ids: [], parking_restriction_ids: [], pet_restriction_ids: [], pool_description_ids: [], rental_dep_incl_ids: [], rental_pay_inc_ids: [], rental_restriction_ids: [], security_ids: [], showing_instruction_ids: [], water_access_ids: [], waterfront_desc_ids: [], window_treatment_ids: [])
end
end
感謝,它的工作。它只顯示模態中的show.html.erb信息。如果可以,我會跟進一個問題,我如何設計這些信息?它目前將只顯示簡單的表演動作,如果我添加任何的div等它只會顯示模式,而不是表演動作信息。 –