Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading assets via mountable engine in rails 4 #32

Closed
jejacks0n opened this issue Jan 1, 2013 · 10 comments
Closed

loading assets via mountable engine in rails 4 #32

jejacks0n opened this issue Jan 1, 2013 · 10 comments

Comments

@jejacks0n
Copy link
Contributor

routes.rb

Dummy::Application.routes.draw do
  mount Teabag::Engine => "/teabag"
end

When you attempt to load an asset from within this engine, the mounted path is prefixed before assets.. so /teabag/assets/teabag-jasmine.js, but this file isn't served at that path -- it's still at /assets/teabag-jasmine.js

What are the plans with this? I totally understand having the assets from an engine served from a different path (and agree), so is there something I'm missing in getting that to work?

@rafaelfranca
Copy link
Member

Sorry but I didn't understand what is you doubt.

assets are not served in the engine prefix since who will serves it is your webserver and it doesn't know anything about how you mounted the engine. So the engine assets are served in the same URL of the application assets.

@jejacks0n
Copy link
Contributor Author

Ok, so that's hard to come back from.. I guess I'll do my best to write a failing test -- or would you rather have a project you can clone to see the issue in?

@rafaelfranca rafaelfranca reopened this Jan 1, 2013
@rafaelfranca
Copy link
Member

@jejacks0n if you could create a project to close would be great.

Thank you

@jejacks0n
Copy link
Contributor Author

no worries. =) so, I understand the confusion a little more now. The case we're talking about is when it's a view from within the engine.

You're correct, if I have a view in your application javascript_include_tag "teabag-jasmine" (an asset from an engine) works fine -- the same is true with a = require directive within an asset in your application.

It's only when attempting to load an asset from within a view in the engine that this happens (like a layout, or controller with it's own views). I can say that it has to do with where the engine is mounted -- and I'll do more investigation into this when I create an example project.

@jejacks0n
Copy link
Contributor Author

@rafaelfranca - Here's an example of using javascript_include_tag from within an engine layout, and how the path at which the engine was mounted is being prepended to the /assets path.

Thanks for taking a look at it. The example app is pointing to master on all it's dependencies -- so it should be current.. it's loading an engine from lib, and the routes for the engine are defined in config/routes.rb -- maybe a little convoluted, but it's the simplest way to accomplish it.

@jejacks0n
Copy link
Contributor Author

I added a commit to Teabag that tries to address this issue (and the duplication one) -- and I'd appreciate feedback/thoughts. I don't like having the shim, but I don't see an obvious alternative.

The project is Teabag, and the commit is 467adc0

The way the test runner works is by using a file matcher to glob spec files. It loads them using javascript_include_tag, which is what leads to the duplicate files being loaded (if they're requiring them more than once).

The issue of prepending the engines path (where it was mounted), generates more complication here, and the fact that the api has changed between rails 3.2 and rails 4 adds to it.

Again, this is mostly about getting things dialed for users, so thoughts would be welcomed.. I avoided manifest files because I want to provide a way to run single spec files from the command line.

@jejacks0n
Copy link
Contributor Author

Tracked the issue back to action_view/helpers/asset_url_helper..

I left a comment on the commit that causes the path to be prepended.

@jejacks0n
Copy link
Contributor Author

Meh, I'm just hammering away on this one waiting for clarification -- in the meanwhile I submitted a pull request that fixes this in rails.

rails/rails#8712

@pboling
Copy link

pboling commented Jan 4, 2013

👍

@guilleiguaran
Copy link
Member

A patch for this was merged in Rails some time ago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants