Closed andrewculver closed 10 months ago
The link to the new send action has this:
<% if can? :create, Newsletters::Issues::SendAction.new(newsletter: newsletter) %>
<%= button_to "Send", [:new, :account, newsletter, :issues_send_action], method: :get, class: 'button-secondary', form: {class: 'button_to'} %>
<% end %>
So, we aren't currently getting these routes below, but I'm assuming this is what we want because newsletter
above is an object (currently, we get another newsletter
namespace nested inside the newsletter
resource block). Also, :issues
needs to be a namespace because we pass :issues_send_action
above.
resources :newsletters do
scope module: 'newsletters' do
resources :issues, only: collection_actions
end
namespace :issues do
resources :send_actions do
member do
post 'approve'
end
end
end
end
namespace :newsletters do
resources :issues, except: collection_actions
end
This setup provides a route that matches the Send
button so we can access the index page, but we ultimately can't perform the Send
action, and this shows up in the logs:
web | Started GET "/account/newsletters/jNeWJL/issues/send_actions/new" for ::1 at 2023-10-26 19:12:58 +0900
web |
web | ActionController::RoutingError (uninitialized constant Account::Issues):
web |
web | Started GET "/account/newsletters/jNeWJL/issues" for ::1 at 2023-10-26 19:12:58 +0900
I can go ahead and make a fix for the routing if what I wrote above is correct, but I still want to make sure this Send
action is working, and I'm currently stuck on that... Will post again if I make more progress.
Can't seem to track down the uninitialized constant Account::Issues
problem. Will try to swing back to this one soon.
@andrewculver Okay, I think I figured out the routing for this one.
resources :newsletters do
scope module: 'newsletters' do
resources :issues, only: collection_actions
namespace :issues do
resources :send_actions, shallow: false do
member do
post 'approve'
end
end
end
end
end
namespace :newsletters do
resources :issues, except: collection_actions
end
This makes sense with the routing that the MarkAllAsReadActions test produces, which is also a targets-one-parent
action:
resources :customers do
resources :notifications
namespace :notifications do
resources :mark_all_as_read_actions do
member do
post 'approve'
end
end
end
end
It's just a little more convoluted because of the deep namespacing we have going on with the targets-one-parent
Newsletters::Issues::SendAction
. Next will be to apply a proper fix to the RoutesFileManipulator and/or the Transformer.
The breadcrumbs partial isn't working, but I haven't looked too much into it yet.
As for as the show page links, this is what we get for the edit page link:
<%= link_to t('.buttons.edit'), [:edit, :account, @send_action], class: first_button_primary if can? :edit, @send_action %>
However, we want something like this:
[:edit, :account, :@send_action.targeted, @send_action]
This is giving problems because @send_action
is namespaced with the targeted object, producing something like this:
edit_account_newsletter_newsletters_issues_send_action
If we can manage to scaffold these properly based on the action type, then we can make this new combination a reality.
I don't want to make too much clutter on this issue, so I'll try to start implementing the logic for this model combination to work and make any additional comments in a pull request.
To recreate this issue:
Add contacts:
Add newsletters:
Let contacts subscribe to newsletters:
You'll need to implement the
valid_newsletters
method ofContact
in./app/models/contact.rb
:Finally, create a send action for the issue:
This appears to work, but when I visit the issue index page, I see this: