Bootstrap4 with Rails 5

时间:2016-09-06 09:09:02

标签: ruby-on-rails ruby twitter-bootstrap twitter-bootstrap-4 bootstrap-4

我跟着official guidethis post没有任何帮助,有人可以对此有所了解吗? (source on github

我的宝石文件:

function sendDataToServer(data) {
var hashids = new Hashids("this is my salt", 50);
//-----------------------------------------------------------
$.ajax({
    type: "POST",
    url: "/Testing.aspx/SaveData",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify({ 'model': data }), 
    success: function (data) {
        var id = hashids.encode(data.d);
        PostResponse(id);
    },
    error: function (ex) {
        alert('Failed to Submit.');
    }
});
}

function PostResponse(id) {
if (id && id.d !== -1) {
    console.log(id);
    alert("Data Submitted Successfully!!!");
    var urll = "/Summary.aspx?Id=" + id;
    window.location.assign(urll);

}
else {
    alert('Failed to Submit.');
}

我的application.scss:

...
#bootstrap
gem 'bootstrap', '~> 4.0.0.alpha3.1'
gem 'sprockets-rails', :require => 'sprockets/railtie'

source 'https://rails-assets.org' do
  gem 'rails-assets-tether', '>= 1.1.0'
end
...

我的application.js:

@import 'bootstrap-sprockets';
@import 'bootstrap';

我的application.html.erb:

//= require jquery
//= require tether
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .

最后,我的index.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <title>DankDist</title>
    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>

我运行了Bundle,重新尝试了<h1>Scale#index</h1> <div class="alert alert-success" role="alert"> <strong>Well done!</strong> You successfully read this important alert message. </div> <p>Hello Worldzz</p> <p>Find me in app/views/scale/index.html.erb</p> <%= params[:id] %> <br/> <%= @id %> Next Page <%= @page +1 %> <hr/> <%= params.inspect %> 而没有任何更改,标题不包含任何样式。

2 个答案:

答案 0 :(得分:2)

有一些错误

  1. ScaleController包含布局false - 因此您的application.html.erb中的样式表导入无法正常工作
  2. @import'bootstrap-sprockets';对于Bootstrap 4 gem来说不是必需的

答案 1 :(得分:-2)

在application.js中的

,尝试按如下方式排列这两行,我注意到它对我有用:

//= require jquery
//= require bootstrap-sprockets