我正在尝试通过远程真实调用打开一个Bootstrap模式,因为我需要将一些参数传递给模态。
所以,我有这段代码:
的index.html
...
<%= link_to("<i class='fa fa-upload'></i>".html_safe, {:controller => :blocked_phone_numbers, :action => :show_modal, :blocked_phone_numbers_group_id => blocked_phone_numbers_groups.id}, :class => "btn btn-primary btn-xs", remote: true) %>
...
<div id="modalImportNumbers">
<%= render partial: 'show_modal' %>
</div>
...
blocked_phone_numbers_controller.rb
def show_modal @blocked_phone_numbers_group = BlockedPhoneNumbersGroup.find(params[:blocked_phone_numbers_group_id]) respond_to do |format|
format.js end end
show_modal.js.erb
$('#modalImportNumbers').html("<%= j render partial: 'show_modal' %>");
$('#modalImportar').modal('show');
_show_modal.html.erb
<div id="modalImportar" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="background-color: #5a4371; color: #fff">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="modalLabel"><%= t(:item_7) %></h4>
</div>
<div class="row">
<div class="col-xs-12 col-md-12 col-md-offset-0">
<div class="modal-body">
<%= form_tag({:action => "import"}, {:multipart => true}) do |form| %>
...
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
的routes.rb
Rails.application.routes.draw do
root 'login#index'
match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
end
问题是我一直收到这个错误:
ActionController :: UnknownFormat(ActionController :: UnknownFormat):
app / controllers / blocked_phone_numbers_controller.rb:25:在`show_modal'
NameError:未初始化的常量Mime :: HTML
我在我的application.js上有jQuery导入,所以,我在这里阅读了许多帖子,但我无法弄清楚发生了什么。
有人可以帮我理解这个错误吗?
我正在使用Rails 5.1和Bootstrap 3.7
谢谢!
答案 0 :(得分:0)
的routes.rb
match '/show_modal' => 'blocked_phone_numbers#show_modal', as: 'show_modal', via: [:get, :post]
index.html.erb
...
<%= link_to show_modal_path(blocked_phone_numbers_group_id: blocked_phone_numbers_groups.id), class: 'btn btn-primary btn-xs', method: :post, :remote => true do%>
<i class='fa fa-upload'></i%>
<%end%>
...
<div id="modalImportNumbers">
<%= render partial: 'show_modal' %>
</div>
...