I have some code in my concerns that I want to call from Action Cable Channel.
Say I have notification channel and I want to call my concerns to update some
values and it does call the method but it does not call the another method
written in application controller.
Say,
In my channel.rb I am using:
class NotificationsChannel < ApplicationCable::Channel
include NotificationChannel
def some_method
create_notification(current_user, quiz)
end
end
NotificationChannel Concerns code:
module NotificationChannel
extend ActiveSupport::Concern
def create_notification(is_current_user, resource)
teacher_user_id = resource.lesson_plan.teacher.user_id
Notification.create(description: "A user with name #{get_user_name(is_current_user)} has liked the #{resource.title}", user_id: teacher_user_id, url: resource_misc_path(resource, "quiz_notification_like_check"))
end
end
Now,
1st problem:
The method get_user_name(is_current_user)
is not accessible in concerns and
it is written in ApplicationController
.
2nd problem:
resource_misc_path(resource, "quiz_notification_like_check" is written in some helper it does not call even helper method.
P.S: I have also noticed the routes having _path
and _url
are also not accessible in Channel.rb
Any suitable workaround?