0

I would like to implement a boostrap modal in my rails application. The button is displaying but when I click on it nothing appears :

/ Trigger the modal with a button
%button.btn.btn-info.btn-lg{"data-target" => "#myModal", "data-toggle" => "modal", :type => "button"} Open Modal
/ Modal
#myModal.modal.fade{:role => "dialog"}
  .modal-dialog
    / Modal content
    .modal-content
      .modal-header
        %button.close{"data-dismiss" => "modal", :type => "button"} ×
        %h4.modal-title Modal Header
      .modal-body
        %p Some text in the modal.
      .modal-footer
        %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close

I think I miss something. Those are my gems installed :

source 'https://rubygems.org'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'haml', '~> 4.0', '>= 4.0.7'
gem 'foundation'
gem 'rails', '4.2.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
...

my application layout :

!!!
%html
  %head
    %title HealthyBox
    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true
    = javascript_include_tag 'application', 'data-turbolinks-track' => true
    = csrf_meta_tags

application.css.scss

@import "bootstrap-sprockets";
@import "bootstrap";
3
  • 1
    Have you added @import "bootstrap-sprockets"; @import "bootstrap"; this lines to app/assets/stylesheets/application.scss ?? Commented Aug 6, 2016 at 10:11
  • I forgot to include it in my post but yes I did Commented Aug 6, 2016 at 10:27
  • 1
    what about //= require bootstrap-sprockets in app/assets/javascripts/application.js ? Commented Aug 6, 2016 at 10:28

1 Answer 1

2

Make sure you followed the below steps

Add below lines to app/assets/stylesheets/application.scss

@import "bootstrap-sprockets"; 
@import "bootstrap";

Note: Make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead

And below line to app/assets/javascripts/application.js

//= require bootstrap-sprockets

It will works fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.