-1

I've spent hours trying to use bootstrap for my rails web app, but it's doing absolutely nothing! I can't call any classes for it!

Here's my 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 %>

Notice the bolded code...the link_to line COMPLETELY IGNORES the bootstrap class, like it doesn't even exist! The button_to line works completely fine...

My Gemfile includes bootstrap (yes, I ran bundle install since updating it):

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"

...

Also, my css file most certainly includes bootstrap:

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

/* mixins, variables, etc. */

/* universal */

body {
  padding-top: 0px;
}

section {
  overflow: auto;
}

...

I also even included in bootstrap in my 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 .

It just won't work! The only thing I can think of is that I am building my rails app as part of a plugin for Redmine, and that's somehow messing everything up...but I don't see how!

UPDATE:

I tried doing this:

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

But I get this cryptic error!

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

I don't understand what that means. Why is it looking for bootstrap file in stylesheets directory?? Google has never heard of this error message!

jan
  • 1,160
  • 1
  • 9
  • 11
ineedahero
  • 488
  • 2
  • 7
  • 22
  • First off, not sure what the `:plugin => 'users'` is attempting to do, but remove that. Second, do you have bootstrap's container div set up in your layout file? – phillyslick Aug 17 '16 at 17:39
  • I need that line because my application is a plugin for redmine. See: http://www.redmine.org/projects/redmine/wiki/Plugin_Tutorial#Improving-the-plugin-views And I don't have any layout file, that's all I have. I don't even know what bootstrap's container div is....? i'm a complete noobie to this stuff – ineedahero Aug 17 '16 at 17:47
  • Ah, indeed. Sorry. You may not need the container div. But check out the docs here: http://getbootstrap.com/css/ You say the `button_to` renders as a bootstrap button? – phillyslick Aug 17 '16 at 17:49
  • No, it just renders as a normal button, sorry if that wasn't clear. – ineedahero Aug 17 '16 at 17:50
  • I see. Not familiar with Redmine, but I still may be able to help. What's the name of the css file that you're @importing bootstrap and bootstrap-sprockets into? – phillyslick Aug 17 '16 at 17:54
  • Thanks for the help! I made a new file called dang.scss in assets/stylesheets directory. I update that stylesheet_link_tag to be 'dang' when I try to get it to work, but it just searches for 'dang.css' instead of 'dang.scss' and I don't understand how to make it work – ineedahero Aug 17 '16 at 17:58
  • The webpage loads (without bootstrap), but the error it throws in the log is: ActionController::RoutingError (No route matches [GET] "/plugin_assets/users/stylesheets/dang.css"): <----that plugin_assets directory contains dang.scss, but not dang.css – ineedahero Aug 17 '16 at 18:01
  • You have asked an almost completely identical question a few hours ago. Re-asking the same question to attract answers is not an acceptable behaviour on StackExchange. – max Aug 17 '16 at 18:24
  • Possible duplicate of [Redmine Plugin Development: can't get bootstrap to do anything :(](http://stackoverflow.com/questions/39001092/redmine-plugin-development-cant-get-bootstrap-to-do-anything) – max Aug 17 '16 at 18:24
  • Yeah I tried putting in the update at the bottom but somehow it created a whole new question, the old question can just be deleted. There I deleted it – ineedahero Aug 17 '16 at 18:25
  • You can delete it yourself. – max Aug 17 '16 at 18:26
  • The scss file isn't being precompiled into css. Check out config/initializers/assets.rb and add /plugin_assets/users/stylesheets/dang.scss to config.assets.precompile like so: `config.assets.precompile += %w( /plugin_assets/users/stylesheets/dang.scss )` That may work. – phillyslick Aug 17 '16 at 21:17

2 Answers2

2

Sorry to disappoint, but if you're building a Redmine plugin using Bootstrap, you're doing it wrong. A plugin (no matter for which platform) should offer a seamless user experience with regards to the host platform itself. Since Redmine is not using Bootstrap, there's no reason you should use it for your plugin.

Instead, you should have a look at the app/views directory in Redmine and use the same HTML elements in your plugin. You'll have a more seamless UI and less need for custom CSS... Hope that helps.

jan
  • 1,160
  • 1
  • 9
  • 11
  • 1
    Ah, very interesting. Thanks for the insight. I guess it's true what they say: don't use a screwdriver to hammer in a nail :) – ineedahero Aug 18 '16 at 15:04
1

Redmine does not support the asset pipeline (see here, 4 year old conversation), which means you cannot use sass/scss files here. You need first to get regular css / js files and import each of them manually in your view.

If you really wish to use bootstrap, you can first install the redmine_bootstrap_kit plugin which provides helpers for you in order to make it more convenient (I am not the owner of this).

For information:

Plugin assets directory is automatically copied each time you run Redmine in the public/plugin_assets/your_plugin folder.

<%= stylesheet_link_tag 'style', :plugin => 'users' %> Will look for style.css file located in public/plugin_assets/users/stylesheets/style.js

<%= javascript_include_tag 'script', :plugin => 'users' %> Will look for script.js file located in public/plugin_assets/users/javascripts/script.js

Please note, generally .js and .css files contain links to additional resources (images, fonts...). Then you need to includes these resources as well in your assets/images / assets/fonts... and make sure the relative paths mentioned in the .js and .css files remain valid.

ste26054
  • 419
  • 3
  • 11