-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Use scenic within a rails engine / component #261
Comments
We are running into this issue as well. We use the same setup, and get the same errors. |
Any updates on this? |
👋 How have folks been solving this? My hacky solution for now is to copy the definitions into both places... |
@shageman We don't have any hacky solutions, have been adding the views in the main app and not the engine, unfortunately. |
Today we ended up fixing this by allowing a
or
This allows you to pass in an extra parameter, if you are calling these from a rails engine. Seems to work well in my tests, even when the engine is referenced from another engine. I couldn't see a way to auto-detect this behavior so this was our next best option. It includes some minor override parameters like this If the scenic team is interested is accepting it as a PR I can put it together. |
@nathanpalmer do you have a fork with the fix for this issue? Running into it myself but I really want to use scenic inside an engine. |
I just submitted a PR with the changes needed to override the root. |
@nathanpalmer Nice! Hoping this gets merged in soon. This is a much needed change for all who are using rails engines and using scenic to create db views. |
@nathanpalmer @derekprior hey guys any updates on this? We've been using scenic for a while inside an engine, and this change would just make our lives so much greater. Eternal thanks would be given back after merging it :D |
@nathanpalmer Any updates on this? |
@alexanderfrankel There is nothing I can do from my side to move this along. The PR is out #287, but will need a response from the scenic team to move forward. |
@nathanpalmer Ok thanks for the update. |
@derekprior It would be a huge help to get this PR merged and this issue resolved. Thanks for all your work on this project! |
My hesitancy here is based in my unfamiliarity with engines. I don't want to commit to a solution only to find out it has headaches down the road. Since I don't know headaches with engines or even best practices with them, I'm a bit at a loss. Can anyone point to prior art for gems that load files being used in an engine? |
@derekprior Thanks for your response; however, @nathanpalmer's solution here: #287 has nothing to do with Rails engines specifically. It just adds more flexibility by allowing the location of the file containing the view definition to be explicitly defined. This solution could be useful for other scenarios outside of using Rails engines if someone wants to define their views in a different file location other than |
I am running into this, as well. However, I tend to prefer running Ideally, views would go in In the case of the engine, the views would start in |
As Derek mentioned, the use case is unfortunately foreign to us and we’d like to see examples of gems that do similar things to accommodate being run inside of an engine. It seems like there are at least three of you in this thread-are any of you able to share examples of gems you’re using in engines within you app that do this? It would be really helpful to have some examples we could poke through to see this. Something like Devise, which has migrations it creates, or another gem with migration generators beyond installing itself like Scenic does would be great. Thanks! |
Sorry, I mean further than those specific gems, if there are code examples you can track down that would be useful. |
I'm not entirely sure what you're looking for. It seems to me that views should be pulled in when |
@calebthompson there is a book on the topic: https://github.com/shageman/component-based-rails-applications-book You can also find a whole host of blog posts and other resources on this approach at https://cbra.info PS: Best to look through the resources... I am biased, both of the above links point to stuff I build/wrote 🙂 |
I am also running into issues using this in an engine.
My current monkey patch is this:
Note: Dummy is the actual name of the rails app that engines generate for testing purposes so I just check for the existence of that module as a way to know that the current ruby process (e.g. test, migrate, etc) is running within the engine itself and not within the host app. For those of you unfamiliar with monkey patching, this simply re-opens the class that is defined within the scenic gem and overwrites a method. This is what it is overwriting: scenic/lib/scenic/definition.rb Line 22 in 3600a48
(I'll add to this comment as I run into other issues and fix them.) |
I just ran into this issue as well. Added scenic inside an engine, and it tries to find the definition from the main application. I might try to solve it with a variation of the monkeypatch above. When it comes to the engine's dummy app, I solved that by just symlinking the views folder in the dummy. This PR would have definitely been nice to have! #287 |
Yep just tried the monkeypatch and it worked, my variation is module Scenic
class Definition
def full_path
<EngineName>::Engine.root.join(path)
end
end
end Seems like the easiest approach for now, despite being a monkeypatch. It would be great to have a standard supported way to do this though. |
@jamesyp where did you put this file? |
@gregkonush I had to do a little PR digging to find it, but I had this monkeypatch in require 'scenic'
require 'scenic_monkeypatch' This worked at the time and I was actually using it in a production codebase, but we don't have the monkeypatch anymore. We "flattened" the engine it was originally in and promoted most of its functionality to the root Rails app (unrelated to Scenic or anything in this issue directly), so no more need for the patch. It'll probably still work but I can't easily check in the project anymore, so can't 100% promise it'll still work for you too. |
Thank you, @jamesyp! This monkey patch still works |
This also worked for me although I had to put the require in require '<engine_name>/scenic_monkeypatch' This all works though, and the views now live in However, I do have an issue with trying to use ❯ rails generate scenic:view my_view
create spec/dummy/db/views
conflict db/views/my_view_v01.sql This is despite |
Ah, looks like this is the problem as it also uses |
We would like to use scenic from within a rails engine. However, the path to the view is not coming up correctly. In my example I have this.
The
products
is the rails engine that is referenced by the main app by this.and to get rails to recognize regular migrations this is put in the
engine.rb
Failing in the component directory
From inside the
components/products
directory when I run arake db:migrate
it seems to be looking for the view intest/dummy/db/views
instead ofdb/views
.20181206151701 CreateExpandedDeals: migrating
Failing in the main app
And if I try to run the migration from the main app itself it's looking for it in
db/views
instead ofcomponents/products/db/views
.20181206151701 CreateExpandedDeals: migrating
Possible fixes?
From looking around PR #237 might fix this, but since that was submitted in February I wasn't sure if it would be merged in any time soon. I haven't seen any feedback from the original author, though @calebthompson did comment on it a day or so ago.
The text was updated successfully, but these errors were encountered: