I asked a question relating to this issue the other day, but encountered another error. I have Index.html.erb with a link_to calling the modal. Once the modal is open I want the body of it to include a partial. Most of my code is from the Bootstrap example because I want to get it working first before I include all my form details in the partial.
gemfile:
group :assets do
gem 'sass-rails', '4.0.1'
gem 'bootstrap-sass', '3.0.2.0'
gem 'bootstrap-modal-rails'
end
application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require bootstrap/modal
//= require_tree .
Index.html.erb (In views/gifts)
<p><%= link_to 'Buy', gift_path(gift), {:remote => true, 'data-toggle' => "modal", 'data-target' => '#myModal', :class => "btn btn-primary ", :id => 'myModal'} %></p>
<!-- Modal -->
<div class="modal fade" id="myModal" 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 'gifts/show' %>
</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 -->
_show.html.erb (In views/gifts/)
<p>This is a gift.</p>
gifts.js.coffee (In assets/javascripts/)
$('#myModal').modal('options')
gifts.controller.rb (Just the show function)
def show
@gift = Gift.find(params[:id])
respond_to do |format|
format.html {render :show}
format.json { head :ok}
end
end
When I click the button in the browser, my rails terminal show this:
Processing by GiftsController#show as JS
When I view the javascript console in my browser, I see a JS error :
[Error] TypeError: '[object Object]' is not a function (evaluating 'f[c](d)')
(anonymous function) (bootstrap.min.js, line 7)
each (jquery.js, line 657)
each (jquery.js, line 266)
modal (bootstrap.min.js, line 7)
ready (application.js, line 23)
fire (jquery.js, line 3049)
fireWith (jquery.js, line 3161)
ready (jquery.js, line 434)
completed (jquery.js, line 105)
Any help would be greatly appreciated.