gpt4 book ai didi

css - 如何将 stylesheet_link_tag 与 bootstrap-sprockets 一起使用?

转载 作者:行者123 更新时间:2023-11-28 08:56:22 27 4
gpt4 key购买 nike

我想从 bootstrap-sass 加载 bootstrap-sprockets gem 在我的布局文件中(例如 application.html.erb )而不是在 application.scss 中。通常建议将 bootstrapbootstrap-sprockets 放在 application.scss 中,如下所示:

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

然后像这样加载到您的 application.scss 中:

  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>

我想像这样加载它们:

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootstrap-sprockets', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootstrap', 'data-turbolinks-track' => true %>

这样我就可以根据某些应用程序变量在 erb 中加载它们。例如使用 bootswatch 和一个实例变量:

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootstrap-sprockets', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootswatch/'+ @account.style.name.downcase + '/variables', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'bootstrap', 'data-turbolinks-track' => true %>

虽然,以这种方式加载这些 Assets 时,我一直收到 RoutingError,即使我在 assets.rb 中的预编译 Assets 中有它,就像这样 Rails。 application.config.assets.precompile += %w( bootstrap-sprockets )

Started GET "/stylesheets/bootstrap-sprockets.css" for 127.0.0.1 at 2015-04-30 13:44:44 -0400

ActionController::RoutingError (No route matches [GET] "/stylesheets/bootstrap-sprockets.css"):
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.1.2) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.1) lib/rails/engine.rb:518:in `call'
railties (4.2.1) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.3) lib/thin/connection.rb:84:in `catch'
thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.3) lib/thin/connection.rb:53:in `process'
thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.7) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.7) lib/eventmachine.rb:187:in `run'
thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
thin (1.6.3) lib/thin/server.rb:162:in `start'
rack (1.6.0) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.0) lib/rack/server.rb:286:in `start'
railties (4.2.1) lib/rails/commands/server.rb:80:in `start'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:75:in `tap'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.1) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:8:in `require'
bin/rails:8:in `<top (required)>'
spring (1.3.4) lib/spring/client/rails.rb:28:in `load'
spring (1.3.4) lib/spring/client/rails.rb:28:in `call'
spring (1.3.4) lib/spring/client/command.rb:7:in `call'
spring (1.3.4) lib/spring/client.rb:26:in `run'
spring (1.3.4) bin/spring:48:in `<top (required)>'
spring (1.3.4) lib/spring/binstub.rb:11:in `load'
spring (1.3.4) lib/spring/binstub.rb:11:in `<top (required)>'
/Users/cj/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/cj/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'

如何让这些 Assets 从 gem 正确加载?

最佳答案

请检查您使用的文件扩展名可能是您使用的是 yourFileName.css 但链接转到了 yourFileName.scss 或 .sass

还要检查你的 Gemfile 是否有

gem 'bootstrap-sass'

也许这个链接对你有用 https://github.com/twbs/bootstrap-sass/issues/692#issuecomment-55091209

http://www.gotealeaf.com/blog/integrating-rails-and-bootstrap-part-1

祝你好运

关于css - 如何将 stylesheet_link_tag 与 bootstrap-sprockets 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29974703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com