-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Rails Engine not properly generating named paths when a used nested resource and render is called through a helper method #8533
Comments
/cc @drogus |
Hi @LockeCole117 I'm having the exact same problem. Did you find a solution or workaround? |
I managed to get the result I wanted by mounting the engine at the top level and then putting a generic resource nesting in the engines route set. Reusing @LockeCole117's example: Engine
Main app
Not ideal, but worked for my use case. Update: |
Hi @mattiassvedhem I'm facing the same problem, could you help us with the helper method you used to set up the routes in the main application? Thanks!! |
Sorry for a super late reply, I haven't been actively on Rails lately and I'm just going through some issues where I was mentioned. I pushed a fix for this. Could one of you test it in your engines and confirm that this is what you're looking for? |
PR was not linked here, a fix is here: #12699 |
Hello,
I've started to experiment with Rails engines, and noticed some odd behavior with Rails Engines and generating names paths when the engine is mounted as a nested resource.
I have an engine that provides a simple todo list with items, and my dummy application creates a
Person
model. The lists can be owned, using a polymorphic associationownable
. I have a helper method defined that is patched intoActiveRecord::Base
namedhas_list
, which gives the model the proper polymorphic association. This is mixed into the application inengine.rb
.The application works perfectly as a nested resource, which is great. However, I wanted to extend the functionality a bit further by creating a few helper methods to generate some "standard" views on the fly (like when showing a person's details, it would be nice if a list of all their todo lists was visible on that page). I opted to create a helper method to accomplish this goal
ownable_list_list
, which would take an ownable object and generate a simple list of all items with links to show/edit/delete. The helper simple calls render on_ownable_list_list.html.erb
in my enginefollowing the advice provided in The Ruby on Rails Guides, I prefixed all of my named links in
bucket_list
(and even triedperson_bucket_list
, which is the name given by the routes in the dummy application). However, I receive the following error when trying to use these helpers:For some reason it looks like when an engine is used as a nested resource, it is not properly being loaded up in
ActiveController
within our application so that we can properly generate our named routes (even when the named route is prefixed by our engine name or our generated name from our application's route file). A reason this behavior does not occur when used as a proper nested resource is that the application relinquishes control to the Engine at that point, which has its own route file and version ofActiveController
. Plus the rendering is done within the scope of the Engine, as opposed to our helper, which "injects" the rendering into the scope of the application.I've put my experiments into a git repo: https://github.com/LockeCole117/bucket_list
Excuse the mess, today I just wanted to see what Rails Engines were capable of.
Thanks for your time.
The text was updated successfully, but these errors were encountered: