2017-08-03 97 views
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">&times;</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 

回答

2

渲染你的表演方法

你也可以告诉Rails渲染,没有时,您可以通过the layout option布局都:

render layout: false 

如果你想仍然呈现布局,如果他们键入show网址到浏览器中,你可以做

render layout: !request.xhr? 

只要坚持,在你的show行动和铁路仍将呈现放映视图然后你可以在你的Ajax调用中把这个响应放到你的模态中。

+0

感谢,它的工作。它只显示模态中的show.html.erb信息。如果可以,我会跟进一个问题,我如何设计这些信息?它目前将只显示简单的表演动作,如果我添加任何的div等它只会显示模式,而不是表演动作信息。 –