I am using Middleman with the activate :asset_hash option in order to compile assets with the hash to force cache invalidation. The problem is that I also load some html templated with Angular templateUrl like this:
function($routeProvider) {
$routeProvider.
when('/dashboard', {
templateUrl: 'templates/dashboard.html',
....
but the dashboard file gets compiled with an hash like templates/dashboard-cc1554f0.html and so Angular doesn't find the file.
Is there a way to pass within the Angular file the same hash that Middleman generates on build ?
I must tell you that I didn't meet this problem (All my js, css and images are hashed, but html files are not). Here is my Gemfile
Gemfile
# If you do not have OpenSSL installed, update
# the following line to use "http://" instead
source 'https://ruby.taobao.org'
gem "middleman", "~>4.0.0"
# Live-reloading plugin
# gem "middleman-livereload", "~> 3.2.0"
# For faster file watcher updates on Windows:
gem "wdm", "~> 0.1.0", :platforms => [:mswin, :mingw]
# Windows does not come with time zone data
gem "tzinfo-data", platforms: [:mswin, :mingw, :jruby]
gem "middleman-minify-html"
gem "middleman-sprockets", "~> 4.0.0.rc"
And here is my config.rb
config.rb
set :css_dir, 'css'
set :js_dir, 'app'
set :images_dir, 'images'
set :layout, false
# Build-specific configuration
configure :development do
set :backend, 'http://localhost:3000'
set :frontend, 'http://localhost:4567/#'
end
configure :build do
set :backend, 'https://api.example.com'
set :frontend, 'https://www.example.com/#'
# For example, change the Compass output style for deployment
activate :minify_css
# Minify Javascript on build
activate :minify_javascript
# Minify HTML files on build, requires gem `middleman-minify-html`
activate :minify_html
# Enable cache buster
activate :asset_hash
# gzip text files
activate :gzip
end
You can see that I use Middleman 4.0.
If your problem remains after upgrading middleman, maybe you can rename your js file to xxx.js.erb and try the helper url_for.
Related
I have a rails '4.2.11.1' application. I want to dissable assets compilation, minifying, pipeline in development. in order to use indium debugger
The rails app seems to be set up with sprokets. so in my config/application.rb I changed to this:
# Enable the asset pipeline
config.assets.enabled = false
also in config/environmetns/development.rb I have this setup:
# Do not compress assets
config.assets.compress = false
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
config.serve_static_files = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
but nothing happens and I get the files:
assets/stixs.self-7246a54effa0c5edaa806b9c4fbc6ba4617c0d80bef8c236f9a4cbcfcf7f0be7.js
finally I get this files not minifyed, or compresed but how can I get that rails work with serving the files in app/assets/javascripts in de delopment environment
Technique Sprockets uses for fingerprinting is to insert a hash of the content into the name
Add this in your development.rb
config.assets.digest = false
I hope that work for you.
Creating a "Hack this site" as a fun project, but stumbled upon a routing error after adding the bootstrap gem, along with jquery.
app/assets/stylesheets/Application.scss
#import "bootstrap";
app/assets/javascripts/Application.js
//= require jquery3
//= require popper
//= require bootstrap-sprockets
Gem file
gem 'rails', '~> 5.2.3'
gem 'devise'
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails'
routes.rb
Rails.application.routes.draw do
resources :pages, path: "", only: [] do
collection do
get :stage1
get :stage2
end
end
get 'resources/Videos'
get 'resources/Photos'
get 'layouts/home'
root '_layouts#home'
get "/pages/:page" => "pages#show"
resources :posts
devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Followed the Bootstrap-rubygem repository installation instructions, and ended up getting the following errors when trying to load the page.
ActionController::RoutingError (No route matches [GET] "/vendor/bootstrap/js/bootstrap.bundle.min.js"):
ActionController::RoutingError (No route matches [GET] "/vendor/jquery/jquery.min.js"):
Got no clue as to what i have done wrong (Probably a lot of things), so i'd appreciate any answers that could lead to resolving this issue!
Found a solution that worked for me (for now atleast).
Aparantly the application.scss had a subfile named application.css under it (using Jetbrains RubyMine).
Deleted the file application.css containing
#import Bootstrap
And now its atleast loading the page properly with the bootstrap css, although the error messages are showing in the server terminal.
Will try to iron out the error messages and post it here if i find a solution to them.
So I updated Ckeditor to 4.2. After I did this, Ckeditor no longer appears in production. Instead, I get the following error in the console:
Uncaught TypeError: CKEDITOR.style.customHandlers[e.type] is not a constructor
I've consulted a few sources, including this post, which claimed the issue was in precompilation. I've edited my application.rb to include Ckeditor in precompilation, but it still doesn't work.
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module DeployTest
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w( ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.active_record.default_timezone = :local
config.time_zone = 'Eastern Time (US & Canada)'
end
end
Weirdly enough, when I turn config.assets.debug = true, Ckeditor starts working again, but my CSS turns off.
Why does config.assets.debug work? Why does it turn off my CSS? And how can I get a permanent solution for ckeditor?
Using ckeditor gem from git solved this issue for me
gemfile:
gem 'ckeditor', github: 'galetahub/ckeditor'
https://github.com/galetahub/ckeditor/issues/719
I have seen a number of variations of this question where all the answers simply suggest removing the coffee-rails gem from the Gemfile (this one and this one).
This is not the answer that I am looking for. I may still want to write some CoffeeScript in the project, I just want JavaScript (.js) to be the default for the Rails generators.
This also means the suggestions to rename .js.coffee to .js every time I generate code is not a desirable solution.
Is there some sort of configuration in Rails I can change to make .js the default, but still leave CoffeeScript enabled (Asset Pipeline should still be able to transpile an .js.coffee files that I may write)?
You can do this by customising the generators config.
config/application.rb
config.generators do |g|
g.javascript_engine :js
end
# or
config.generators.javascript_engine = :js
You can see more available configuration options here.
Comment out gem 'coffee-rails', '~> 3.2.1' in your Gemfile
when using the bootstrap-sass gem i have loaded my css files properly, however have been receiving an error when i try loading the javascript files. I have followed the procedure of loading javascript from https://github.com/twbs/bootstrap-sass however when I view my webpage on localhost I receive the error "couldn't find file 'bootstrap'"
This is what my application.js file looks like - Any help would be much appreciated!
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 vendor/assets/javascripts of plugins, if any, 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.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
// Loads all Bootstrap javascripts
//= require bootstrap
//= require_tree .
From the Rails 4 the :assets group isn't used anymore, please remove the group from Gemfile:
Rails 4.0 removed the assets group from Gemfile. You'd need to remove that line from your Gemfile when upgrading. You should also update your application file (in config/application.rb):
Bundler.require(:default, Rails.env)
I got it to work by removing gem 'bootstrap-sass', '~> 3.0.3.0' out of the assets group in gemfile! YAY
Did you bundle install and make sure you are loading application.js (from the assets pipeline).