2016-08-17 87 views
-1

我花了幾個小時試圖爲我的rails web應用程序使用引導程序,但它完全沒有做任何事情!我無法爲它調用任何類!Bootstrap在Redmine插件中不起作用

這裏是我的index.html.erb:

<div class="center"> 
    <h1>Welcome to the User Database</h1> 
</div> 

<div class="jumbotron"> 
    <h2> 
    This is the home page for the User Database. 
    </h2> 

    **<%= link_to "Add new entry", new_user_path, class: "btn btn-primary" %> 
    <%= button_to "Search", users_search_path, class: "button", :method => :get %>** 
</div> 

<!-- User Image --> 
<div class="center"> 
    <%= image_tag('user.jpg', :plugin => 'users') %> 
</div> 

<!-- Style sheet --> 
<% content_for :header_tags do %> 
<%= stylesheet_link_tag 'style', :plugin => 'users' %> 
<% end %> 

通知粗體代碼...的的link_to線完全忽略引導類,就像它根本不存在!該button_to線工作完全正常...

我的Gemfile包括引導(是的,我跑了包,因爲它的更新安裝):

source 'https://rubygems.org' 

if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.5.0') 
    abort "Redmine requires Bundler 1.5.0 or higher (you're using #{Bundler::VERSION}).\nPlease update with 'gem update bundler'." 
end 

#Trying to get bootstrap...? 
gem 'bootstrap-sass', '3.3.6' 

gem "rails", "4.2.3" 
gem "jquery-rails", "~> 3.1.3" 

... 

而且,我的CSS文件肯定包括引導:

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

/* mixins, variables, etc. */ 

/* universal */ 

body { 
    padding-top: 0px; 
} 

section { 
    overflow: auto; 
} 

... 

我甚至還包括在引導我的application.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files 
// listed below. 
// 
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 
// 
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// compiled file. JavaScript code in this file should be added after the last require_* statement. 
// 
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 
// about supported directives. 
// 
//= require jquery 
//= require jquery_ujs 
//= require turbolinks 
//= require bootstrap-sprockets 
//= require_tree . 

它只是不行!我能想到的唯一的事情就是我正在構建我的Rails應用程序,作爲Redmine插件的一部分,並且這不知怎麼搞亂了所有內容......但我不知道該怎麼做!

UPDATE:

我試着這樣做:

<% content_for :header_tags do %> 
    <%= stylesheet_link_tag 'application', :plugin => 'users' %> 
<% end %> 

但我得到這個神祕的錯誤!

ActionController::RoutingError (No route matches [GET] "/plugin_assets/users/stylesheets/bootstrap"): 

我不明白這是什麼意思。爲什麼它在樣式表目錄中尋找引導文件?谷歌從來沒有聽說過這個錯誤信息!

+0

首先,不確定':plugin =>'users''試圖做什麼,但刪除它。 其次,你的佈局文件中是否設置了bootstrap的容器div? – phillyslick

+0

我需要該行,因爲我的應用程序是redmine的插件。請參閱:http://www.redmine.org/projects/redmine/wiki/Plugin_Tutorial#Improving-the-plugin-views我沒有任何佈局文件,這就是我所擁有的。我甚至不知道什麼bootstrap的容器div是....?我是一個完全noobie這個東西 – ineedahero

+0

啊,的確。抱歉。你可能不需要容器div。但請查看這裏的文檔:http://getbootstrap.com/css/ 你說'button_to'呈現爲引導按鈕? – phillyslick

回答

2

對不起,令人失望,但如果你使用Bootstrap構建Redmine插件,那麼你做錯了。一個插件(無論是哪個平臺)應該提供關於主機平臺本身的無縫用戶體驗。由於Redmine沒有使用Bootstrap,因此您沒有理由將其用於您的插件。

相反,您應該看看Redmine中的app/views目錄,並在插件中使用相同的HTML元素。您將擁有更加無縫的用戶界面,並且不需要自定義CSS ...希望有所幫助。

+1

啊,非常有趣,謝謝你的洞察力,我猜這是真的,他們說:不要用螺絲刀敲擊指甲:) – ineedahero

1

Redmine不支持資產管道(請參閱here,4年的對話),這意味着您無法在此處使用sass/scss文件。您需要首先獲取常規的css/js文件並在視圖中手動導入每個文件。

如果你真的想使用引導程序,你可以先安裝redmine_bootstrap_kit插件,爲你提供助手以使它更方便(我不是這個的所有者)。

的信息:

插件assets目錄每次在public/plugin_assets/your_plugin文件夾中運行管理平臺的時間自動複製。

<%= stylesheet_link_tag 'style', :plugin => 'users' %> 將尋找位於public/plugin_assets/users/stylesheets/style.js

<%= javascript_include_tag 'script', :plugin => 'users' %> 將尋找位於public/plugin_assets/users/javascripts/script.js

請注意,一般.js.css文件包含鏈接到其他資源(圖片,字體script.js文件style.css文件。 ..)。然後,您還需要將這些資源包含在您的assets/images/assets/fonts ...中,並確保.js.css文件中提到的相對路徑保持有效。