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

with_assets enforces awkward file structure #36

Open
Fodoj opened this issue Dec 25, 2017 · 4 comments
Open

with_assets enforces awkward file structure #36

Fodoj opened this issue Dec 25, 2017 · 4 comments

Comments

@Fodoj
Copy link

Fodoj commented Dec 25, 2017

Let's say I have two concepts: payment and article, both have compex forms which I want to make as cells. Structure is this:

app/concepts/payment/cell/form.rb
app/concepts/payment/view/form.erb
app/concepts/payment/view/form.js
app/concepts/article/cell/form.rb
app/concepts/article/view/form.erb
app/concepts/article/view/form.js

Now guess what - I can't require both form.js files using approach proposed in guides. I would do:

  config.cells.with_assets = ["payment/cell/form", "article/cell/form"]

What I am doing next is adding both form.js fies to my application.js, right? So it would look like:

//= require form
//= require form - OOOPS

And, after doing some tests, I see that sprockets would just pick first form.js, ignoring the other. What can I do about it? Well:

Come up with uniq names for asset fies

app/concepts/payment/view/payment_form.js
app/concepts/article/view/article_form.js
//= require payment_form
//= require article_form

This would work fine, except that it looks stupid :-)

Use full path to assets

Idea, at least as it seems to be, is to filestructure without any weird prefixes and just include assets by using full path:

//= require concepts/payment/view/form
//= require concepts/article/view/form

The only this is that due to the way cells-rails adds paths to assets path this won't work.

What I ended up doing is to add this line to application.rb:

    config.assets.paths << Rails.root.join("app", "concepts")

Now in my application.js I can easily do:

//= require payment/view/form
//= require article/view/form

So, I don't know. My "workaround" works fine, just wanted to discuss this issue. I can make a PR that updates with_assets helper to do something more reasonable. Opinions, thougts?

@apotonick
Copy link
Member

Oh totally open to more work on this. I added the with_assets code years ago and just left it there, so I'm sure we can make it cooler. The full path makes a lot of sense to me. This could be standard in 5.0 (which will be based on Trailblazer::Cell).

@Fodoj
Copy link
Author

Fodoj commented Dec 25, 2017

I hear a lot about cells 5.0, but hardly found any roadmap or actively developed branch for it on github - where I can learn more about it?

@apotonick
Copy link
Member

There is none - I'm busy with a million other gems, I was hoping for @timoschilling to dump his brain. Happy to chat about it.

@artur79
Copy link

artur79 commented Nov 30, 2018

@Fodoj solution works like a charm, saved me a lot of time when I had some a bit similar issue with config.cells.with_assets

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

3 participants