我有一个患者模型,其中各个字段显示在一个表格中,每行都有一个编辑和销毁按钮。我希望编辑按钮打开一个引导模式来编辑该特定患者。为此,我有一个_form.html.erb部分。当我加载页面时,所有部分都呈现:“渲染患者/ _form.html.erb”。当我按下任何编辑按钮时,模态不会出现。
这是我的病人/ index.html.erb
<div class="media">
<div class="media-body">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Email</th>
<th>DOB</th>
<th>Number</th>
<th>Address 1</th>
<th>Address 2</th>
<th>Address 3</th>
<th>Address 4</th>
</tr>
</thead>
<tbody class ="patientsTable">
<% @patients.each do |patient| %>
<tr>
<td><%= patient.name %></td>
<td><%= patient.surname %></td>
<td><%= patient.email %></td>
<td><%= patient.date %></td>
<td><%= patient.number %></td>
<td><%= patient.address1 %></td>
<td><%= patient.address2 %></td>
<td><%= patient.address3 %></td>
<td><%= patient.address4 %></td>
<td><%= link_to 'Chart', href="/landingpage/xrays" %></td>
<td><%= link_to 'Edit', '#', 'data-target' => "#myModal_#{patient.id}", 'data-toggle' => 'modal' %>
<div class="modal fade" id='<%= "myModal_#{patient.id}" %>' tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<%= render 'patients/form', patient: patient %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</td>
<td><%= link_to 'Destroy', patient, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<h4>Add Patient</h4>
<%= form_for Patient.new do |f| %>
<label>Name</label>
<%= f.text_field :name %>
<label>Surname</label>
<%= f.text_field :surname %>
<label>Email</label>
<%= f.text_field :email %>
<label>DOB</label>
<%= f.text_field :date %>
<label>Number</label>
<%= f.text_field :number %>
<label>Address 1</label>
<%= f.text_field :address1 %>
<label>Address 2</label>
<%= f.text_field :address2 %>
<label>Address 3</label>
<%= f.text_field :address3 %>
<label>Address 4</label>
<%= f.text_field :address4 %>
<%=f.submit %>
<% end %>
这是我的PatientsController
class PatientsController < ApplicationController
def index
@patients = Patient.all
@patient = Patient.new
end
def show
end
def new
@patient = Patient.new
end
def edit
@patient = Patient.find(params[:id])
end
def destroy
@patient = Patient.find(params[:id])
@patient.destroy
redirect_to patients_path
end
def create
@patient = Patient.create(patient_params)
@patient.save
redirect_to patients_path
end
def update
respond_to do |format|
if @patient.update(patient_params)
format.js {}
else
format.html { render action: 'edit' }
format.json { render json: @patient.errors, status: :unprocessable_entity }
end
end
end
private
def patient_params
params.require(:patient).permit(:name, :surname, :email, :date, :number, :address1, :address2, :address3, :address4)
end
end
这是我的病人/ _form.html.erb
<%= form_for(patient, remote: true) do |f| %>
<% if @patient.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@patient.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @patient.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :surname %>
<br>
<%= f.text_field :surname %>
</div>
<div class="field">
<%= f.label :email %>
<br>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :date %>
<br>
<%= f.text_field :date %>
</div>
<div class="field">
<%= f.label :number %>
<br>
<%= f.text_field :number %>
</div>
<div class="field">
<%= f.label :address1 %>
<br>
<%= f.text_field :address1 %>
</div>
<div class="field">
<%= f.label :address2 %>
<br>
<%= f.text_field :address2 %>
</div>
<div class="field">
<%= f.label :address3 %>
<br>
<%= f.text_field :address3 %>
</div>
<div class="field">
<%= f.label :address4 %>
<br>
<%= f.text_field :address4 %>
</div>
<div class="actions">
<%= f.submit %>
</div>
我无法弄清楚为什么模态没有出现。如果你能发现为什么我会感激任何帮助。
<div class="modal fade show" id='<%= "myModal_#{patient.id}" %>' tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
.
.
.
.
.
</div><!-- /.modal -->
添加一个类显示以及模态和淡入淡出。如果那似乎不起作用在insted中添加类