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

Default address showing users/3/notifications? #64

Closed
RailsCod3rFuture opened this issue Mar 25, 2018 · 22 comments
Closed

Default address showing users/3/notifications? #64

RailsCod3rFuture opened this issue Mar 25, 2018 · 22 comments

Comments

@RailsCod3rFuture
Copy link

RailsCod3rFuture commented Mar 25, 2018

How do you remove /:target_type/:target_id from route address? and leave only /notifications. Is it possible with your gem? I'm using notify_to :users, with_devise: :users

@simukappu
Copy link
Owner

Hi,

Currently, you cannot use route address by activity_notification's router, but you can do it by writing the routes with notification_controller in routes.rb yourself.
I would like to add this function for using route address to activity_notification's router. If you can send the pull requests, I would appreciated it.

Thanks

@truongnmt
Copy link

truongnmt commented Oct 21, 2018

@simukappu Can you explain a bit detail? Some sample code is really useful!

@truongnmt
Copy link

truongnmt commented Oct 21, 2018

on rails routes I see:

     open_all_user_notifications POST       /users/:user_id/notifications/open_all(.:format) activity_notification/notifications#open_all {:target_type=>"users"}
          move_user_notification GET        /users/:user_id/notifications/:id/move(.:format) activity_notification/notifications#move {:target_type=>"users"}
          open_user_notification POST       /users/:user_id/notifications/:id/open(.:format) activity_notification/notifications#open {:target_type=>"users"}
              user_notifications GET        /users/:user_id/notifications(.:format)          activity_notification/notifications#index {:target_type=>"users"}
               user_notification GET        /users/:user_id/notifications/:id(.:format)      activity_notification/notifications#show {:target_type=>"users"}
                                 DELETE     /users/:user_id/notifications/:id(.:format)      activity_notification/notifications#destroy {:target_type=>"users"}

@truongnmt
Copy link

@RailsCod3rFuture any idea bro?

@RailsCod3rFuture
Copy link
Author

I will look into this error tomorrow. I've been swamped lol. But, I really need to get the routes fixed, so that nothing malicious can happen between users.

@RailsCod3rFuture
Copy link
Author

Could @simukappu give us a simple demonstration controller/route config that satisfies the requirements we're looking for? The generic controller that is included, seems pretty vast, & I don't have the time/schedule to make serious errors/mistakes. I'm getting ready to test this build on a live server. Please, post a working gist that we can look into and analyze to remove the user/id out of the address bar. Thanks. @truongnmt

@simukappu
Copy link
Owner

simukappu commented Nov 5, 2018

Hi @RailsCod3rFuture, @truongnmt,

I have added implementation for default routes with devise integration to activity_notification gem.
Can you try this new function from development blanch and check if it fits in your use case?

You can add the routes as follows:

notify_to :users, with_devise: :users, devise_default_routes: true

And you will see the routes like this:

open_all_notifications POST   /notifications/open_all(.:format) activity_notification/notifications_with_devise#open_all {:target_type=>"users", :devise_type=>"users"}
     move_notification GET    /notifications/:id/move(.:format) activity_notification/notifications_with_devise#move {:target_type=>"users", :devise_type=>"users"}
     open_notification POST   /notifications/:id/open(.:format) activity_notification/notifications_with_devise#open {:target_type=>"users", :devise_type=>"users"}
         notifications GET    /notifications(.:format)          activity_notification/notifications_with_devise#index {:target_type=>"users", :devise_type=>"users"}
          notification GET    /notifications/:id(.:format)      activity_notification/notifications_with_devise#show {:target_type=>"users", :devise_type=>"users"}
                       DELETE /notifications/:id(.:format)      activity_notification/notifications_with_devise#destroy {:target_type=>"users", :devise_type=>"users"}

Thanks!

@truongnmt
Copy link

Hello @simukappu, thanks so much for reaching out. Sorry but may I ask after checkout to develop, how can I test, does that mean build gem again? 😅

@RailsCod3rFuture
Copy link
Author

@truongnmt @simukappu You have to target the branch and rebuild the gem, I believe.

@RailsCod3rFuture
Copy link
Author

I will check it out now. Thanks for extending the functionality for your gem.

@RailsCod3rFuture
Copy link
Author

@truongnmt gem 'activity_notification', :git => 'https://github.com/simukappu/activity_notification', :branch => 'development'

@RailsCod3rFuture
Copy link
Author

@simukappu I'm receiving errors when I access the index.html.erb using <%= link_to "Notifications", notifications_path %> . The routes don't seem to be working with the new changes. Its still seeing the old routes.

Started GET "/notifications" for 127.0.0.1 at 2018-11-06 14:46:59 -0500
   (3.0ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by ActivityNotification::NotificationsWithDeviseController#index as HTML
  Parameters: {"target_type"=>"users", "devise_type"=>"users"}
  User Load (5.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
  User Load (1.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 2], ["LIMIT", 1]]
Unpermitted parameters: :target_type, :devise_type, :target_id
  ActivityNotification::Notification Load (6.0ms)  SELECT "notifications".* FROM "notifications" WHERE "notifications"."target_id" = $1 AND "notifications"."target_type" = $2 AND "notifications"."opened_at" IS NULL AND "notifications"."group_owner_id" IS NULL ORDER BY "notifications"."created_at" DESC  [["target_id", 2], ["target_type", "User"]]
  ActivityNotification::Notification Load (1.0ms)  SELECT  "notifications".* FROM "notifications" WHERE "notifications"."target_id" = $1 AND "notifications"."target_type" = $2 AND "notifications"."opened_at" IS NOT NULL AND "notifications"."group_owner_id" IS NULL ORDER BY "notifications"."created_at" DESC LIMIT $3  [["target_id", 2], ["target_type", "User"], ["LIMIT", 10]]
  Rendering activity_notification/notifications/default/index.html.erb within layouts/application
  Rendered activity_notification/notifications/default/index.html.erb within layouts/application (1981.8ms)
Completed 500 Internal Server Error in 35855ms (ActiveRecord: 27.0ms)


  
ActionView::Template::Error (undefined method `open_all_user_notifications_path' for #<#<Class:0x000000000a3c7f58>:0x000000000a3c52d0>
Did you mean?  open_all_notifications_path):
    1: <div class="notification_wrapper">
    2:   <div class="notification_header">
    3:     <h1>Notifications to <%= @target.printable_target_name %> <%= link_to open_all_notifications_path_for(@target, @index_options), method: :post, remote: true do %><span class="notification_count"><span class="<%= 'unopened' if @target.has_unopened_notifications?(@index_options) %>"><%= @target.unopened_notification_count(@index_options) %></span></span><% end %></h1>
    4:   </div>
    5:   <div class="notifications">
    6:     <% if @index_options[:with_group_members] %>
  
app/views/activity_notification/notifications/default/index.html.erb:3:in `_app_views_activity_notification_notifications_default_index_html_erb__632639667_85886780'
Processing by ExceptionHandler::ExceptionsController#show as HTML
  Parameters: {"target_type"=>"users", "devise_type"=>"users"}
Completed 500 Internal Server Error in 205ms (ActiveRecord: 0.0ms)

are you facing the same issue @truongnmt ???

@simukappu
Copy link
Owner

Ups, this seems error at default view template. I will check it later.

@RailsCod3rFuture
Copy link
Author

Ok. Let me know when to recheck.

@simukappu
Copy link
Owner

I have tested it with both route confuguration

notify_to :users, with_devise: :users
notify_to :users, with_devise: :users, devise_default_routes: true

Can you try this configuration at first?

@RailsCod3rFuture
Copy link
Author

It's working now! PERFECT. You should push this feature up to production. I had to split the routes.

@simukappu
Copy link
Owner

Thank you!
I think default views should work with devise_default_routes only. I will update it shortly and release as a new version.

@RailsCod3rFuture
Copy link
Author

ok. I'll be waiting for it.

@simukappu
Copy link
Owner

Just released as v1.6.0.
https://rubygems.org/gems/activity_notification/versions/1.6.0
Try simple default routes with new v1.6.0 gem. Please give us feedback if you have any issues or more requests.
Thanks!

@RailsCod3rFuture
Copy link
Author

Great, I will be switching over to the new gem.

@aert
Copy link

aert commented Nov 20, 2019

notify_to :users, with_devise: :users
notify_to :users, with_devise: :users, devise_default_routes: true

Hey @simukappu , great work here !

I noticed the two lines are required, otherwise an exception is thrown as open_user_notification_path is missing.

@truongnmt
Copy link

truongnmt commented Apr 4, 2020

Great work here!!! Thanks man!

I just tried to make it work with:

notify_to :users, with_devise: :users, devise_default_routes: true

and I need to tweak a few places at the default view, passing devise_default_routes: true on creating link.

Do you mind if I open a PR just to explain those stuff in README @simukappu

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

4 participants