2016-08-17 90 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文件中提到的相对路径保持有效。