Closed gazayas closed 1 year ago
Ok, this takes care of the path issue. I stopped using the URL to determine what path we want because I figured it was a bad idea, and the idea to check the *_id
attributes came to me this morning after I took a step away from this PR for a bit.
We still have to add the routes manually (from this comment. I plan on working in the RoutesFileManipulator
here next), but as far as the links themselves, I think the work on this one is done for target-one-parent actions.
You will also have to add this code from bullet_train-core
.
I haven't tested this with other actions, but I could see the same issue happening. For now, I'll just keep the changes for the targets-one-parent
action.
The only thing I don't like about this is that we're making calls to the database multiple times if we use the same helper method more than once in a view. It's not the end of the world, just something to consider moving forward.
Closes #93. This PR also assumes the routes setup spelled out in this comment.
The Problem
Actions can be namespaced like this:
Listings::PublishAction
. However, when the routes are deeply nested and parents in the hierarchy are resources, we don't get the proper routes.In the model setup in #93, we have the following:
Super scaffolding generates links to urls with arrays like this:
This would produce a path like this, because the
send_action
class isNewsletters::Issues::SendAction
:This wasn't working because newsletters is a resource, and
[:account, send_action]
has no knowledge of the newsletter resource, raising aNoMethodError
. What we really need is this:It should be noted that in some places, the parent resource was being scaffolded correctly for collection actions. For example, in #93 I brought up this code:
The link here works for collection actions, but when we need both the
newsletter
resource and thesend_action
resources, we weren't scaffolding the proper routes, and it just showed up in different places like[:account, send_action]
.The Solution
What this PR does is, it takes the current url path and builds the action model path based off of that. So it does the following:
path_method
, then passes the arguments we got in step 3So ultimately we're calling this:
send(path_method, *object_arguments)
Which in our example results in this:The reason for using the requests url is that I'm assuming we only want these links when we're on a page in the namespace. For example, we wouldn't call the action from another random resource in the application.
Implementation
In our views like _action.html.erb in
bullet_train-themes-light
, we would do the following:I will have to make joint PR which should include the following:
If we need documentation to explain what's going on though, I can write that.