-
Notifications
You must be signed in to change notification settings - Fork 0
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
Override Orchid Routes in Apps #16
Comments
From Jess: "... you can't override a named route. Like |
This thread is for rails 3, but might have something we can try out: https://stackoverflow.com/questions/5997527/overriding-named-routes-provided-by-rails-3-engines |
Okay, it looks like the app's routes load before the generator's routes load. This means that any gnarly code can be done on the engine's side and most casual users won't need to know about it. There is likely a better way to do this, but I'm thinking...what if we run each of orchid's routes through a check. If there isn't currently a route with that name, we add it. If there is, we skip the orchid version (maybe outputting a warning about it being overridden?). |
So, using the above idea about only loading orchid routes if no similarly named app route, I mocked up a branch: This does appear to work in general cases. The bad news is that Cather specifically wants the letters at http://guides.rubyonrails.org/routing.html#advanced-constraints |
I believe that this now addresses the above concern, also. My questions now are:
|
Code is reviewed and ready, but Jess said she'll move documentation to README. We had discussed it before and I can't remember if we came to any conclusion. Do we want to add further constraints on the |
I think I would prefer that the item path's id stays fairly open in orchid, but we could lock it down by app / project as needed? |
Excellent point. I agree. |
Can this issue be closed? |
After I add documentation to the PR and we merge it :) |
Oh! I thought all the routes stuff had already been merged, my bad |
Oh, sorry I misread which issue this was when I posted that. There is the routing with Passenger deployment bug I'm working on now though, so that's a reason to leave it open. Will close this once that's sorted out. |
Orchid routes don't work when the main app is deployed via Phusion Passenger because of how it spawns processes. It must be set to the 'direct' SpawnMethod for the routes to be present in the app. This can only be set vhost-wide and we don't want to do that for all future Orchid-based Rails apps. Looking into how to modify the code to be compatible. |
Previous approach with `require_relative`, aside from feeling very hacky and not the Rails way, breaks when deployed via Phusion Passenger because of its smart spawning method to save resources and speed up extra app process creation: https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/ Symlink `config/routes.rb` from `config/initializers/` to properly load `ROUTES` constant before main app's routing is processed Remove class variables as they don't work well with Passenger smart spawning either. Instead: - Only call draw method from `routes.rb` if `ROUTES` defined - Directly check drawn routes to determine whether Orchid should draw its routes when draw method called Check whether home path drawn, as apps will always need a home path and its location should never change, though its controller and view will often be overridden in the main app Remove `scope url_prefix` which breaks routes when deployed via Passenger, our preferred method of deploying Rails apps at sub-URIs Change `Orchid::Routing` to a module since it is never instantiated Use `module_function` scoping for draw method per style guide: https://github.com/bbatsov/ruby-style-guide#module-function Close #16
Right now I don't know how to override or alter routes that were drawn by the orchid engine. I haven't read too much about it, yet, but spitballing ideas
http://edgeguides.rubyonrails.org/engines.html#routes
The text was updated successfully, but these errors were encountered: