Skip to content
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

Are namespaces supported? #56

Closed
josephbridgwaterrowe opened this issue Jan 31, 2018 · 4 comments
Closed

Are namespaces supported? #56

josephbridgwaterrowe opened this issue Jan 31, 2018 · 4 comments

Comments

@josephbridgwaterrowe
Copy link

I am having problems adding notifications under an admin namespace.

Some background, the app has a single public page which is used to submit some information and the remaining functionality is used by administrators.

# /config/routes.rb
Rails.application.routes.draw do
  # Public routes (a form on the home#index POST's to information#create
  resources :information, only: %i(create)
  root to: 'home#index'

  # Admin section
  namespace :admin do
    devise_for :users, ...

    notify_to :users, controller: '/activity_notification/notifications'

    # Some other information model related routes
    resources :information, only: %i(edit index show update)
  end
end

The user and notifiable models are basic:

# /app/models/user.rb
class User < ApplicationRecord
  acts_as_notifier
  acts_as_target email: :email_address, email_allowed: true


# /app/models/information.rb
class Information < ApplicationRecord
  acts_as_notifiable :users,
                     email_allowed: true,
                     notifier: ->(user, key) { user },
                     notifiable_path: ->(information, key) { [:admin, information] },
                     tracked: true,
                     targets: -> (information, key) { User.where(role: 'admin').to_a },
                     printable_notifier_name: ->(user, key) { user }

However, when visiting http://localhost:5000/admin/users/1/notifications

I receive the following error:

undefined method `open_all_user_notifications_path' for #<#<Class...

    # @todo Must handle devise namespace
    def open_all_notifications_path_for(target, params = {})
      send("open_all_#{target.to_resource_name}_notifications_path", target, params)
    end

Which I assume is caused by the target being User and the view helpers not supporting nesting, unless of course I'm (hopefully) missing something simple.

@josephbridgwaterrowe
Copy link
Author

It turns out I may have solved this myself after looking over the other open issues, #46 actually gave me the idea to use a scope around the notifications instead.

I'll continue and report my progress.

@simukappu
Copy link
Owner

simukappu commented Feb 5, 2018

Hi @josephbridgwaterrowe,

Thank you for your contribution. The activity_notification gem is not currently tested with nested routes or scope. Since the gem uses internal simple function to find configured routes, maybe dynamic routing doesn’t work in these conditions.

I would appreciate it if you could give us enhancements to support nested routes or scope.
Thanks!

@josephbridgwaterrowe
Copy link
Author

@simukappu, thanks for your response.

It turns out I was able to scope it after all, for example:

  # config/routes.rb
  scope 'admin' do
    notify_to :users, with_devise: :admin_user, with_subscription: true
  end

Thanks again and I will close this issue as I was able to solve the problem with the above code.

@simukappu
Copy link
Owner

Support for routing scope has been released as v1.6.0.
https://rubygems.org/gems/activity_notification/versions/1.6.0
See CHANGELOG.md
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants