Skip to content

with_assets enforces awkward file structure #36

@Fodoj

Description

@Fodoj

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions