images and other assets #30

Closed
samselikoff opened this Issue Dec 20, 2014 · 71 comments

Projects

None yet
@samselikoff
Contributor

where should we put assets? I have an image in my ember cli app's public folder, but it's not showing up in the rails app.

@rwz
Collaborator
rwz commented Dec 20, 2014

I'd suggest using EmberCLI for javascript only for now, and use conventional Rails Assets Pipeline for stylesheets and other assets including images.

@samselikoff
Contributor

hmmmmmmmmmmmmmm

@samselikoff
Contributor

what if I don't like the asset pipeline? 😛

There are many ember cli addons that bring in components with both js and css, how will these work?

@rwz
Collaborator
rwz commented Dec 20, 2014

`¯_(ツ)_/¯

Any suggestions?

We could investigate if it's possible to append public directories to Rails ActionDispatch::Static handler.

@rondale-sc
Collaborator

you can use include_ember_stylesheet_tags and include_ember_script_tags. Addons will push the css they need into the files included by the former. (I think)

@rondale-sc
Collaborator

As far as images are concerned, I'm not sure what to do here. If you just throw them into the rails app they'd be availble but you'd not have the asset helpers in ember land

@samselikoff
Contributor

right. ok I'll think more about this.

I tend to like the frontend/backend separation when doing ember/rails apps, so this rubs me a bit the wrong way. But so far I'm liking the integration.

I'll let you all know how it goes. Thanks for the work by the way, the project has a great api!

@rondale-sc
Collaborator

Thanks! And thanks for tryin' it out. :))

[edit] Let us know if you have any thoughts on this btw. More eyes lookin' at it the better.

@rondale-sc
Collaborator

@rwz Isn't the result of the build symlinked into the asset path of rails. If that is true then images should be served already. (will test as soon as I can, prolly not tonight)

@rwjblue
Contributor
rwjblue commented Dec 21, 2014

I believe that we need to change https://github.com/rwz/ember-cli-rails/blob/dec085b0a67c3ff05367ccc6b7384d148f6df23a/lib/ember-cli/app.rb#L127 to just symlink dist_path.

Does that make sense?

@rwz
Collaborator
rwz commented Dec 21, 2014

Well, then the assets path's gonna be awkward, like "/assets/frontend/assets/frontend.js"

@rwjblue
Contributor
rwjblue commented Dec 21, 2014

True, but things would work ;)

@rwjblue
Contributor
rwjblue commented Dec 21, 2014

If you have an addon that adds things to the ember-cli its public tree, those assets will end up in dist/addon-name/whatever-file-name.foo. This is super useful if you want your addon to be able to lazily load assets.

For example: I have an addon that adds a rich-text-editor component using TinyMCE, obviously I do not want all of TinyMCE in my vendor.js (despite its name it isn't very tiny) so I have it in the public tree which ends up at dist/ember-cli-rich-text-editor/tiny-mce.js, then during the component's first initialization it ensures that asset is loaded. That way the consuming app doesn't need the asset to impact vendor.js size, and it only takes a hit on loading if you use the component.

It is also nice to have images in public/images/ and fonts in public/fonts/ (I realize that all of these could be done by Rails too).

tldr; I think more things from the EmberCLI world will work out of the box, if the all of dist/ were available....

@rwz
Collaborator
rwz commented Dec 21, 2014

Now, I don't think just changing symlink from "dist/assets" to just "dist" is gonna accomplish anything here. The reason is that your Ember component will expect TinyMCE to be available at /ember-cli-rich-text-editor/tiny-mce.js, but assets pipeline will be expecting /assets/frontend/ember-cli-rich-text-editor/tiny-mce.js which is different.

Alternative solution will be to keep assets pipeline the way it's now, but also attach dist folder as an alternative public path. So Rails will serve /ember-cli-rich-text-editor/tiny-mce.js the same way as if you put in public folder.

@rwjblue
Contributor
rwjblue commented Dec 21, 2014

@rwz - Setting the EmberCLI baseURL to /assets/frontend/ in config/environment.js and everything works PERFECTLY....

This is one way that folks deploy to S3 for example (just set the baseURL to the final deployment path).

@rwjblue
Contributor
rwjblue commented Dec 21, 2014

The baseURL could likely be set by the addon (and the path would be provided via an ENV var like the new SUPPRESS_JQUERY thing we added) so everything "just works" magically (who doesn't like magic?).

@rwz
Collaborator
rwz commented Dec 21, 2014

What do you think of my mount-dist-to-public idea?

@rwjblue
Contributor
rwjblue commented Dec 21, 2014

Ya, mounting dist to public should be fine (and might also help the deployment situation). But if we do this, then why do we need to do both things (symlink dist/assets/ into tmp/ember-cli-rails-asdfasdf and dist/ to public/frontend/)? Also, we should still update the addon to set the baseURL to where the assets will end up at...

@chrisdevor

I created PR #56 that may be worth looking at regarding this issue. It basically copies the contents of dist/assets into public/assets and then updates manifest.json to reference the correct fingerprinted files for app_name.js, app_name.css, vendor.js and vendor.css. Thoughts?

@rondale-sc
Collaborator

@chrisdevor I'm going to try to take some time tomorrow to look at #56 more closely. :)

@chrisdevor

Sounds good. It should work with a stand alone rails s environment or rails s in combination with ember s --proxy:http://0.0.0.0:3000 (@ localhost:4200). Let me know if you have any questions or issues.

@chrisdevor

Looks like broccoli-asset-rev has a built in generateRailsManifest option that I overlooked. I'm going to investigate using that and probably push a few more fixes/updates on that branch I made over the weekend.

@TeknoFiend

Seems like setting baseURL would not be the right thing to do since that has other effects, no?

@ljuti
ljuti commented Feb 16, 2015

Any advice on how to use generateRailsManifest or other means to get assets into production. I have assets, such as images, in my Rails asset pipeline that I'd like to use in Ember templates. Assets are compiled properly, but templates do not have fingerprinted URLs to them.

@oliver----

Just want to contribute a problem scenario which we are facing currently.
Unfortunately I am not experienced enough in ember-cli(-rails) to contribute to a solution.

We are using the font-awesome addon: https://github.com/lfridael/ember-cli-font-awesome
It adds its assets to "/fonts" https://github.com/lfridael/ember-cli-font-awesome/blob/master/index.js#L21-L27
But eventually these are not available in the rails app.
Any advice welcome, thanks!

@rainkinz

I had the same issue and ended up copying the fonts dir into app/assets/stylesheets. It works, but I'm sure it's not the recommended solution.

@oliver----

@rainkinz ah, interesting fix for this particular problem. Thx.

@gniquil
gniquil commented Mar 11, 2015

I have a hack, kind of works and would like to know if this is ok.

First, in a helper for the Rails app say app/helpers/application_helpers, I have

module ApplicationHelper
  def image_assets
    image_asset_dir = Rails.root.join('app', 'assets', 'images')

    assets = {}

    %w(.jpg .png .jpeg).each do |file_ext|
      Dir.glob(File.join(image_asset_dir, "**", "*#{file_ext}")).each do |absolute_path|
        file = absolute_path.sub(File.join(image_asset_dir, '/'), '')
        assets[file] = asset_url(file)
      end
    end

    assets
  end
end

with this defined, create this file app/assets/javascripts/assets.js.erb with the following content

<% environment.context_class.instance_eval { include ApplicationHelper } %>

window.assets = window.assets || {};

window.assets.images = <%= raw(image_assets.to_json) %>;

now, assuming you have the normal frontend.html.erb file, just do the usual:

<%= javascript_include_tag 'assets' %>

Once you do this, you will have access to window.assets.images in the environment. From here it's easy to wrap this in an Ember helper say rails-asset-url and use it like

{{rails-asset-url 'logo.png'}}

Since all the assets are in a .js.erb file, it is precompiled so the Dir.glob should have no impact in production. If this works, I think it shouldn't be too hard to roll into ember-cli-rails. :)

What do you think?

@gniquil
gniquil commented Mar 11, 2015

Just as a follow up, the rails-asset-url helper will simply be:

import Ember from 'ember';

export function railsAssetUrl(file) {
  return window.assets.images[file];
}

export default Ember.Handlebars.makeBoundHelper(railsAssetUrl);

@rwz?

@juggy
juggy commented Mar 12, 2015

I added

config.assets.paths << File.join(Rails.root, "front-end/dist/")

to my rails config. It works in dev, but I did not deploy in prod yet, so I am sure it will need some rework.

@rondale-sc
Collaborator

@gniquil This sounds really interesting. Do you have this working on a ember-cli-rails project?

@rwz
Collaborator
rwz commented Mar 12, 2015

@gniquil LGTM. We could definitely pull something like this into the gem and implement the helper in the npm-addon.

@steve9001

What about a helper for SCSS to load background images or fonts? Would that be possible as well?

@rondale-sc
Collaborator

Currently toying around with the idea of re-running broccoli-asset-rev (with the Rails asset manifest) after the files have been added to the asset path. This would ensure that urls would point to the rails fingerprints. Still trying to figure out if this is going to be possible. Will post more when I know more.

@gniquil
gniquil commented Mar 20, 2015

@steve9001 I don't think my hack will work with SCSS, as it injects the asset paths into the html as a global, which can be used in javascript for runtime lookup (i.e. once the page has been loaded and the ember app is running). SCSS on the other hand is compiled beforehand.

And for this reason, I don't consider my hack as a full blown solution. However, if one lives by the recommendation of only using styles through rails as oppose to Ember, my hack I believe is a workable.

@gniquil
gniquil commented Mar 20, 2015

@rondale-sc I will post something tonight. You can also take a look at my PR (the change is very minor and perhaps you could try it in a dummy app).

@gniquil
gniquil commented Mar 20, 2015

For better or worse, here's a sample app showing how it works

https://github.com/gniquil/ember-cli-rails-with-assets.git

@TeknoFiend

I've created PR #132 as a proposed solution to this problem. It (optionally) turns the Ember CLI fingerprinting back on and bypasses the Rails asset pipeline so we don't get two sets of fingerprints.

Assuming you configure your Ember CLI app (or consumed addon) to export the images/fonts into dist/assets instead of dist you should be able to use relative references from CSS/SCSS files to use them. You can also reference them from Rails views with the image_path helpers but not from CSS in Rails b/c of the way Rails works (maybe someone with more knowledge of Rails could submit a PR there).

I kind of agree with @samselikoff on liking the frontend/backend distinction but I know that there are cases where you may run into wanting/needing to reference files form both sides. I do think it makes sense to move away from the asset pipeline where possible though. Seems like the future is to have all the frontend be in the frontend.

@steve9001

It seems like ember-cli-rails is for hybrid apps that need some pages rendered in Rails. We decided we could live with no Rails generated pages and were able to eliminate ember-cli-rails. We now have basically this setup:

  1. Disable the asset pipeline in application.rb with config.assets.enabled = false
  2. Make a symlink from public/assets to frontend/dist/assets
  3. The root controller action serves frontend/dist/index.html
  4. Use url('images/logo.png') in SCSS to refer to frontend/public/assets/images/logo.png
  5. Use ember build --prod instead of rake assets:precompile for production (broccoli-asset-rev works correctly)
  6. Use ember build -w for development and integration tests (install Watchman, and you might need to stop when you do a git rebase)

ember-cli-rails was an essential bridge to enable our spike of re-writing our front end with Ember, but the production deployment limitations made it necessary to move on, but the impact on development workflow turns out to be minimal in our situation.

@rondale-sc
Collaborator

@steve9001 This is an awesome comment! I really like that setup for ember-cli-rails! Going to digest this a bit and maybe re-evaluate some things in the readme.

@seanpdoyle
Collaborator

@rondale-sc @rwz where do we stand on this?

Are there any PR's that look like good candidates?

@rounders

I've been wondering about this as well. I'd like to be able to create an ember addon that has some css, and an image that is used as a background image. I can get this to work in development by doing the following:

I place both the image and the css file in the vendor directory of the addon and then add
the following code to the included hook in the addon:

app.import('vendor/mystylesheet.css');
app.import('vendor/myimage.png', {
      destDir: 'assets'
    });

mystylesheet.css has the following in it:

background: url(flags16.png) no-repeat;

This works ok in development, but not in production.

@TeknoFiend

@seanpdoyle @rounders I wouldn't mind some input on my PR #132

Not sure if it makes sense for anyone else's setup but it's the way we'd like to do it for our projects (and a shared internal addon).

@rounders

@TeknoFiend I don't yet fully understand all of the problem to intelligently comment on the PR.

One of my concerns with the current implementation of ember-cli-rails is that addons that include files in the 'public' folder cannot be used with ember-cli-rails

According to the Ember Cli docs, the public folder within an addon will be available in the application as /your-addon/*
This is currently not the case with ember-cli-rails. And if I understand correctly, I don't think PR #132 will fix that problem either.

@TeknoFiend

Yeah I probably shouldn't have mentioned the addon, that's a complicating factor. For our own internal addon we added logic to put the addon's assets into dist/assets/ADDON_NAME so they're available (see [https://github.com/ember-cli/ember-cli/issues/3313]). That's not helpful if you're using third-party addons that don't do the same thing.

My PR was really trying to address having images referenced from CSS that both live in your Ember CLI app.

@rockwood

What's the current status on exposing ember-cli assets through rails? We're using ember-cli-deploy so we need fonts and images to be self-contained within the frontend ember app, yet still be available via rails during development. For that use case, it seems like @rwz's idea to add ember's dist/ to the rails public path would work best.

@skylar
skylar commented Jul 7, 2015

I've been thinking about this quite a bit today and reviewing the PRs in this thread.

I'll start by offering that I think it would be fantastic for ember-cli-rails to follow the Ember CLI approach of being opinionated and convention-based. That likely means that it primarily serves one approach to combining Ember and Rails functionality, and it does that really well with little or no effort on part of the adopter. Whether migrating an existing app or writing a new app coupling both technologies, that seems to suggest a project that:

  • Uses Ember for the frontend
  • Uses Rails for the backend/API
  • May mount other rack apps (rails, sinatra, resque_web, etc.) at various other endpoints or serve up traditional Rails views on some endpoints

To me, this establishes Ember is the primary owner of the frontend assets, and thus the Ember CLI asset pipeline should be deferred to for asset precompilation. I think @TeknoFiend's #132 captures this approach well by simply letting the precompiled assets bypass rails' asset pipeline and move directly to public/assets/<name>. It allows the Ember apps to take full advantage of the awesome broccoli-asset-rev and keeps Ember CLI apps mostly unaffected and unaware of their Rails host.

This means (by ember-cli-rails convention) Rails would utilize asset paths from an Ember app (or addon) a the primary source of front-end assets (e.g. /assets/frontend/images/logo.png). Also, rails views are free to have their own copies of certain assets if that's more convenient. (Symlinks also help here).

👍 for pulling #132 and perhaps passing through some other helpful environment variables for the Ember CLI asset compilation (e.g., ASSET_PREFIX)

@skylar
skylar commented Jul 8, 2015

After working a bit with #132 I noticed it doesn't work well with Rails 3 since it uses a different manifest file format. Since mucking with Rails' generated manifest is brittle, I took a different approach in leveraging the broccoli-asset-rails manifest during app initialization to update the in-memory manifest DB.

For those that want to embrace fingerprinting or assets management primarily in Ember, #181 implements a simple flag to avoid butting heads w/ Rails, while still making ember-generated assets usable from the Rails side.

@Leooo
Leooo commented Sep 12, 2015

@gniquil's code works well for me in Heroku in the two following cases:

  • Assets precompiled locally before deploying (rake assets:precompile RAILS_ENV=staging)
  • Assets precompiled by Heroku during the deployment and saved in Heroku's slug.

Unfortunately I have a third use case where assets are precompiled by Heroku during deployment, but not saved in the slug (asset path is in .slugignore): I'm using a CDN for assets so don't need to save the folder in Heroku (and I want to reduce my slug size).

Anyone has an Idea of how to solve this? Thanks

@Samsinite

@rwz we need to solve this. Looks like no path of action has been decided and this has been sitting open for a long time. Seems like a major deal breaker.

@seanpdoyle
Collaborator

Setting the EmberCLI baseURL to /assets/frontend/ in config/environment.js and everything works PERFECTLY....
-- @rwjblue

Has anyone tried this? Has anyone had success with that approach? It seems like the least amount of effort to get things working.

@skylar
skylar commented Oct 13, 2015

@seanpdoyle My feedback is, that it this point, the issue is not specific enough to come to a conclusion quickly. For the baseURL trick, it solves some deploy scenarios, but less so question on flexibility of placing assets in the ember project directory, and having it then handled in a way compatible with the asset_pipeline.

Perhaps we close this and more specific new issues?

As for #181 - it wasn't the least amount of effort, but it turned out as a pretty elegant solution for us - we've been using in production for 3 months. I'm happy to help adapt/discuss this PR if it's interesting for others.

@rwz
Collaborator
rwz commented Oct 13, 2015

@rwz we need to solve this. Looks like no path of action has been decided and this has been sitting open for a long time. Seems like a major deal breaker.

@Samsinite Unfortunately I don't do Ember and use ember-cli-rails for quite a while now.

ember-cli-rails is an abandonware at this point. :(

@skylar
skylar commented Oct 13, 2015

@rwz do you of a previous contributor who might be interested in taking ownership of the project? (i.e., pulling fixes, etc.)

@seanpdoyle
Collaborator

@rondale-sc are you still interested in ember-cli-rails?

If not, @rwz I'm willing to oversee the project.

@Samsinite

@skylar I like your #181 solution, I think that there should be support for letting ember-cli own some/all assets, asset compilation, and asset fingerprinting which is likely required for shared use as of right now. If fact, I think it should be the default.

No reason to not let ember-cli own and fingerprint its assets and update the rails manifest to resolve to ember's manifest for the files in which it generated. Especially since ember-cli should know what it needs to do.

@skylar
skylar commented Oct 13, 2015

Thanks @samsinite. In #181 any assets in the rails assets Dir get handled by the pipeline. Same for ember assets if the flag is off. If the flag is on then assets are copied untouched but are added to the manifest

@rwz
Collaborator
rwz commented Oct 13, 2015

@seanpdoyle that'd be great. You already have commit bit, so feel free to do what you think is right here. :)

@Samsinite

Since #181 didn't work with rails 4, and I realized that broccoli-asset-rev can create manifest files, I ended up just creating a rake task that:

  1. precompiles rails assets using RAILS_ENV=production bundle exec rake assets:precompile
  2. precompiles ember assets using ember cli with fingerprinting: DISABLE_FINGERPRINTING=false ./node_modules/.bin/ember build --environment=production
  3. removes the ember assets created by the rails pipeline
  4. copies the fingerprinted assets into the expected location
  5. reads both the ember-cli manifest file and the rails pipeline manifest file and replaces all associated ember assets in the rails pipeline manifest file with the associated ember asset in the ember-cli manifest file

A gist of my rake task is here: https://gist.github.com/Samsinite/632e99134b43e96d7162, this worked perfect for Rails 4.2

Also, in the ember-cli-build.js file, you need to set generateRailsManifest to true:

/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    fingerprint: {
      generateRailsManifest: true
    },
    ...
  });
  return app.toTree();
};
@seanpdoyle seanpdoyle added the bug label Oct 23, 2015
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 2, 2015
@seanpdoyle seanpdoyle Symlink `/dist` to Asset Pipeline
Closes [#30].

[#30]: #30
ebb91b8
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 2, 2015
@seanpdoyle seanpdoyle Modify `ENV.baseURL`
Closes [thoughtbot/ember-cli-rails#30].

Detects the presence of `process.env.RAILS_ENV` to signal that the Ember
app is running (or being compiled from) within a Rails app.

If that's the case, change the `baseURL` to be `/assets` plus the
`ENV.modulePrefix`.

[thoughtbot/ember-cli-rails#30]: thoughtbot/ember-cli-rails#30 (comment)
6bec50f
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 2, 2015
@seanpdoyle seanpdoyle Modify `ENV.baseURL`
Closes [thoughtbot/ember-cli-rails#30].

Detects the presence of `process.env.RAILS_ENV` to signal that the Ember
app is running (or being compiled from) within a Rails app.

If that's the case, change the `baseURL` to be `/assets` plus the
`ENV.modulePrefix`.

[thoughtbot/ember-cli-rails#30]: thoughtbot/ember-cli-rails#30 (comment)
a170018
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 7, 2015
@seanpdoyle seanpdoyle Generate Rails `manifest.json` 0c56435
@seanpdoyle seanpdoyle referenced this issue in rondale-sc/ember-cli-rails-addon Nov 7, 2015
Merged

Prepare URLs for Sprockets Asset Pipeline #17

@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 7, 2015
@seanpdoyle seanpdoyle Generate Rails `manifest.json` 728fc51
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Generate Rails `manifest.json`
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Generate Rails `manifest.json` when building from Rails.
* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
67f7dc5
@seanpdoyle
Collaborator

@samselikoff @Samsinite @skylar (and anyone else still following this thread).

I've done some work to make frontend assets work.

Could you all try the following:

  • Install the master branch of `ember-cli-rails:
# Gemfile
gem 'ember-cli-rails', github: 'thoughtbot/ember-cli-rails'
  • Install the master branch of ember-cli-rails-addon:
"ember-cli-rails-addon": "git://github.com/rondale-sc/ember-cli-rails-addon.git",
  • Make sure that your frontend assets are in the EmberCLI public/assets directory.

If you'd like an example repo to work off, you can check out ember-cli-rails-heroku-example.

Please try running locally, and if you can push to staging, try deploying as well.

If you can't deploy to a staging site, please try faking production:

$ RAILS_ENV=production rake assets:precompile
$ RAILS_ENV=production rails server
$ open http://localhost:3000

Please come back to this thread and bring attention to any issues.

If this resolves your issues, I'll merge the branches into their respective masters and give each library a minor version bump, since the URLs being served will have been changed.

@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

* Symlink `dist/` directly to Asset Pipeline
* Merge EmberCLI-generated `manifest.json` into Sprocket's
* `manifest.json`. Since we now defer to EmberCLI, we no longer need to
  manually resolve asset URLs.
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
7bb39ff
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon][#17].

* Symlink `dist/` directly to Asset Pipeline
* Merge EmberCLI-generated `manifest.json` into Sprocket's
* `manifest.json`. Since we now defer to EmberCLI, we no longer need to
  manually resolve asset URLs.
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
cc86b91
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Merge EmberCLI-generated `manifest.json` into Sprocket's
* `manifest.json`. Since we now defer to EmberCLI, we no longer need to
  manually resolve asset URLs.
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
cab4fa4
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
78e01d0
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
cbe418b
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
c9f88c4
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
b9a82a1
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
3e6d532
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
6b12e75
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 8, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
23ad882
@seanpdoyle seanpdoyle referenced this issue in rondale-sc/ember-cli-rails-addon Nov 8, 2015
Closed

Setup via `$ ember addon ember-cli-rails-addon` #18

@Samsinite

Sweet! Thanks @seanpdoyle I'll test locally, then in a staging env and let you know how it goes.

@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 9, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
a633e66
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 9, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
b587a3b
@seanpdoyle
Collaborator

@Samsinite (and anyone else waiting on a fix):

Any success with #30 (comment)?

@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
6952166
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
588124b
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
50924ab
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
bb7a457
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
2a3f513
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
57f32c1
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
941350f
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
ce3336e
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
a581509
@seanpdoyle seanpdoyle added a commit that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Defer to EmberCLI build pipeline
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
bb4b03c
@seanpdoyle seanpdoyle added a commit to rondale-sc/ember-cli-rails-addon that referenced this issue Nov 10, 2015
@seanpdoyle seanpdoyle Prepare URLs for Sprockets Asset Pipeline
Initial steps toward closing [thoughtbot/ember-cli-rails#30][#30].

* Prepend Sprockets path to EmberCLI assets.
* Default fingerprinting to no generate `MD5` hash when building in
  `development`.

[#30]: thoughtbot/ember-cli-rails#30
2236b35
@seanpdoyle seanpdoyle closed this in #250 Nov 10, 2015
@skylar
skylar commented Nov 10, 2015

@seanpdoyle thanks. i haven't had a chance to check it out, but it looks like you already got relevant testing and were able to merge? also, looks like your approach in #250 has rails-sprockets merge the broccoli-generated manifest during an asset build (similar to #181)? If so, then that's the core of the pull we were looking for.

@seanpdoyle
Collaborator

@skylar I ended up backing out of using the manifest.

Didn't end up needing it.

I've merged the Addon PR and the Gem PR into their respective masters, but I haven't released yet.

I'd still love as much user-testing as possible, since I only have experience with a subset of the gem's use cases

This was referenced Nov 12, 2015
@kayakyakr

@seanpdoyle, there's a lot of information in this thread and I'm trying to get through it. I think I ran into an issue with adding the dist path to the asset pipeline: this doesn't work when we are skipping the asset pipeline, as in an nginx, self-hosted assets situation. I haven't dug very deeply, yet, but in production, the pipeline isn't running at all, so adding the dist directory does not work.

Will probably solve, for now, by writing a task that loops through and copies the assets from dist to deploy.

@seanpdoyle
Collaborator

@kayakyakr I'm not sure of your particular use case, but as of 0.6.0, ember-cli-rails deliberately avoids integrating with the asset pipeline.

In what ways doesn't ^0.6.0 support your use case?

@kayakyakr

Sorry, that was the older stuff. So serving stuff via Rack::File is great when you're using the rack server to serve assets. If assets are being served directly via nginx or in some other form, they will need to be copied to assets on deploy.

I wrote a deploy task to link the assets in the ember build to the public assets folder:

after "deploy:compile_assets", :ember_assets do
  on roles :web do
    execute :ln, '-sf', "#{release_path}/tmp/ember-cli/apps/home/assets/*", "#{release_path}/public/assets/"
  end
end
@seanpdoyle
Collaborator

@kayakyakr I see.

That capistrano task looks good to me, although it depends on /tmp/ember-cli/apps/home pointing to your app (which it currently does, but isn't exactly part of the gem's public API).

I recommend serving the Ember assets over a CDN, since it relies on EmberCLI's public API, and isn't dependent on the underlying (private) directory structure.

@kayakyakr

Eventually, but we're not ready to publish to a CDN, so I'll have to hack it for now.

@skylar
skylar commented Feb 19, 2016

@seanpdoyle I finally had a chance to checkout your latest build. The code looks great! Better yet, I was able to migrate from 0.3.x to 0.7.x without too much of a fuss. Given the nature of our app, we have to handle at least 25% of our routes in rails (eg, custom controller/actions) when bootstrapping the ember app. (The others are just pass-throughs to 1 of 2 standard ember-app renders).

What this means is that mount_ember_app seems to not be an option since we need to define many custom route handlers. (Are there provisions for this in your new system?) The workaround for this is simply adding EmberCli[:app name].build in our app controller method (eg, ApplicationController::render_ember_app). Also, I had to add a call to mount_ember_assets to the route file.

There are a couple of asset bugs to sort through, but nothing major. It seems the issues from this PR are more or less handled for me too.

That said, I was wondering, do you see any specific issues for "legacy" ember-cli-rails apps that call build on their own and simply mount the asset paths? Anything I might be missing?

@Samsinite

@skylar you can see mount_ember_app defined here, and that it is just creating a get scope with a bunch of default options. You can really just define your own get scope however needed. And of course, if it is the last defined route, others will have precedence too. We keep mount_ember_app defined as the last route in our route file, even after this:

  # Clobbers all /api/* routes, Keep this as the second to last route in the routes file
  match '/api/*path', to: 'ember_application#api_not_found', via: :all

So our route looks something like this:

  # other routes and stuff...

  # Clobbers all /api/* routes, Keep this as the second to last route in the routes file
  match '/api/*path', to: 'ember_application#api_not_found', via: :all

  # Mount the ember app
  mount_ember_app :frontend, to: "/", controller: 'ember_application'

Our controller looks like this:

class EmberApplicationController < EmberCli::EmberController
  skip_before_action :authenticate

  def api_not_found
    render status: 404, nothing: true
  end
end

Here is an example template with extra stuff:

<%= render_ember_app ember_app do |head, body| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>
  <% body.append do %>
    <% if Rails.application.secrets.server_status == 'development' %>
      <div id="pipeline-flag">
        <div class="development-flag">
          <p>Development</p>
        </div>
      </div>
    <% end %>
    <% if Rails.application.secrets.server_status == 'staging' %>
      <div id="pipeline-flag">
        <div class="staging-flag">
          <p>Staging</p>
        </div>
      </div>
    <% end %>
  <% end %>
<% end %>

Really, this gem is much more flexible and awesome with the latest set of updates. We also keep using a proxy, with ember serve in development for speed and developer happiness, as the build times are slow and it also handles reloading without any extra setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment