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

Issues with broadcast_to and single table inheritance #673

Open
dmbrooking opened this issue Aug 27, 2024 · 0 comments
Open

Issues with broadcast_to and single table inheritance #673

dmbrooking opened this issue Aug 27, 2024 · 0 comments

Comments

@dmbrooking
Copy link

We have a model using STI.

Our base model looks like this:

class Project < ApplicationRecord
  broadcasts_to ->(project) { project}, partial: 'projects/project' // have to explicitly set partial to handle child classes
  ...
end

and one of the child classes is

class Project::Holiday < Project
  ...
end

For this issue, the first line of the partial is <div id="<%= dom_id(project) -%>">. This is where our error is happening.

When we create a new Project, everything works fine. When we create a new Project::Holiday, the broadcast job errors with the following error:

Failure/Error: <div id="<%= dom_id(project_holiday) -%>">
     
     ActionView::Template::Error:
       undefined local variable or method `project_holiday' for an instance of #<Class:0x000000013e0db058>

How would we handle this to work with STI?

Things we have tried:

  1. Passing in a locals object to the partial. This did not work.
  2. Passing in an object param to broadcasts_to. This did not work.
  3. Adding the broadcasts_to line to project/holiday.rb but this just seemed to be ignored. We confirmed that by removing the partial param on the base class and this errored with Missing partial project/holidays/_holiday with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.

Any ideas?

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

No branches or pull requests

1 participant