2017-08-03 6 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

あなたはあなたのショー方法

をレンダリングするときにもなしでレンダリングするためにレールを伝えることができthe layout optionを渡すことができますすべてのレイアウト:

render layout: false 

あなたは彼らがブラウザに表示するURLを入力する場合は、

render layout: !request.xhr? 

を行うことができ、まだレイアウトをレンダリングしたい場合はちょうどあなたのshowアクションとレールにまだショーのビューをレンダリングすることを堅持Ajaxコールで応答を受け取り、それをあなたのモーダルに入れることができます。

+0

ありがとう、それは働いた。これは、モーダル内にshow.html.erb情報を表示するだけです。フォローアップの質問があれば、どうすればその情報をスタイルできますか?現在のところ、プレーンショーアクションのみを表示します。divなどを追加すると、ショーアクション情報ではなくモーダルが表示されます。 –

関連する問題