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

Using Perspectives in an Engine #2

Open
emerson-h opened this issue Sep 16, 2014 · 5 comments
Open

Using Perspectives in an Engine #2

emerson-h opened this issue Sep 16, 2014 · 5 comments

Comments

@emerson-h
Copy link

I'm working on an application that uses a component based approach, so we have several engines. I would love to keep the views as dumb as possible and Perspectives seems to be a great way to do that.

The project is setup something like this:

/var/www/
   /app
   /bin
   /components
      /foo_engine
         /app
            /assets
            /perspectives
               /bar
                  show.rb
            /mustaches
               /bar
                  show.mustache
            ...
        /bin
        ...
   /config
   ...

When visiting the engine's routes in the URL (e.g. foo_engine/bars/1/show), perspectives raises this error:

No such file or directory @ rb_sysopen - /var/www/app/mustaches/bar/show.mustache

It seems like it's not recognizing that it's running within an engine, so it's looking for mustaches in the top level app folder.

@a-warner
Copy link
Contributor

@emerson-h you should be able to configure the template path to whatever you want. The default railtie configures it to be app/mustaches relative to the project root (link), but you can change that:

Perspectives.configure do |c|
  c.template_path = app.root.join('whatever', 'you', 'want')
end

@emerson-h
Copy link
Author

@a-warner Thanks! I saw that a couple of minutes ago as I was looking for a possible fix. It seems like it might be more robust to have the railtie default the template path to be relative to the directory of the including railtie, so for instance, if included in an engine, it would default to <engine_path>/app/mustaches/ for that engine.

If you think that's a good idea, I'm happy to submit a pull request

@a-warner
Copy link
Contributor

@emerson-h i'd love to see a pull request. the template path should be relative to the root of the including engine/app for sure.

@emerson-h
Copy link
Author

@a-warner I'm working on a fix for this, but so far it's proving more intractable than I hoped.

A stop-gap solution is to symlink the mustaches folder from an engine into the including application.

@a-warner
Copy link
Contributor

ugh, that's a deeply unsatisfying stop-gap though 😄

it seems like Rails probably handles this pretty well, I guess by allowing railties/engines to append to the view_paths instead of having one total view path for the app? maybe a similar solution here would make sense? (although how do you distinguish between users/show in your app vs the engine..or maybe that's not a big deal?)

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

2 participants