cells-rails icon indicating copy to clipboard operation
cells-rails copied to clipboard

with_assets enforces awkward file structure

Open Fodoj opened this issue 7 years ago • 4 comments

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?

Fodoj avatar Dec 25 '17 08:12 Fodoj

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).

apotonick avatar Dec 25 '17 09:12 apotonick

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?

Fodoj avatar Dec 25 '17 09:12 Fodoj

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.

apotonick avatar Dec 25 '17 19:12 apotonick

@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

artur79 avatar Nov 30 '18 16:11 artur79