mardi 5 février 2019

Pop up window in rails is not shown on clicking of a button

I am working in an application where on clicking a button I should pop up a small window with a drop-down list of users. on-licking any one of those users, I should get user_id and it should be saved in one more model

my team controllers view has

new.html.erb // contains my form code

_new.html.erb // contains modal code

new.js.erb //contains js code

implemented in the following way

//controller

  def new
        @team=Team.new

        respond_to do |format|
          format.html
          format.js
        end

      end

//_new.js.erb

$("#modal-window").find(".modal-content").html("<%= j (render 'new') %>");
$("#modal-window").modal();

//new.html.erb

    <%= form_for :team, :html => { :class => "form-horizontal team" } do |f| %>

        <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
          <%= f.label :team_name, :class => 'control-label col-lg-2' %>
          <div class="col-lg-10">
            <%= f.text_field :team_name, :class => 'form-control' %>
          </div>
        </div>

    <%= link_to 'Select Captain', teams_new_path,  {:remote => true, 'data-toggle' =>  "modal", 'data-target' => '#modal-window', class: 'btn btn-primary btn-lg'}  %>
    <div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
       <div class="modal-content"></div>
      </div>
    </div>

        <div class="form-group">
          <%= f.label :ground_name, :class => 'control-label col-lg-2' %>
          <div class="col-lg-10">
            <%= f.text_field :ground_name, :class => 'form-control' %>
          </div>
        </div>

        <div class="form-group">
          <div class="col-lg-offset-2 col-lg-10">
            <%= f.submit nil, :class => 'btn btn-primary' %>
            <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                      teams_new_path, :class => 'btn btn-default' %>
          </div>
        </div>
        </div>
      <% end %>

//_new.html.erb

    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">x</button>
      <h4 class="modal-title" id="myModalLabel">Modal title</h4>
    </div>
    <div class="modal-body">
    <%= select(:user_id, User.all.map{|e| [e.full_name, e.id]},{ include_blank: "Please select"}, multiple: true ) %>
    </div>
    <div class="modal-footer">
      <button class="btn btn-primary">Save</button>
    </div>

now its displaying my new.html.erb but no actions are undertaken

//log shows

Started GET "/teams/new" for 127.0.0.1 at 2019-02-06 10:24:52 +0530
Processing by TeamsController#new as JS
  Rendering teams/new.js.erb
  Rendered teams/_new.html.erb (0.3ms)
  Rendered teams/new.js.erb (1.8ms)
Completed 200 OK in 9ms (Views: 6.5ms | ActiveRecord: 0.0ms)

pop up window is not showing please help me with correct guidance

Aucun commentaire:

Enregistrer un commentaire