Skip to content

ActionCable lesson: Fix lesson flow for Rails 8 missing channels directory#30913

Merged
CouchofTomato merged 3 commits intoTheOdinProject:mainfrom
bittoby:fix/actioncable-missing-channels-rails-8
Mar 23, 2026
Merged

ActionCable lesson: Fix lesson flow for Rails 8 missing channels directory#30913
CouchofTomato merged 3 commits intoTheOdinProject:mainfrom
bittoby:fix/actioncable-missing-channels-rails-8

Conversation

@bittoby
Copy link
Copy Markdown
Contributor

@bittoby bittoby commented Mar 18, 2026

Because

Rails 8 no longer auto-generates the app/channels/ directory when running rails new. This causes learners to get stuck when the lesson asks them to open app/channels/application_cable/connection.rb because the file does not exist yet.

This PR

  • Reorders actioncable_lesson.md so that rails generate channel message runs before editing connection.rb
  • Updates the expected generator output in both actioncable_lesson.md and websockets_and_actioncable.md to reflect Rails 8 behavior
  • Removes outdated references to files "already existing" since Rails 8 creates all Action Cable files on first channel generation
  • Adds a brief note in both lessons explaining that Rails 8 does not generate Action Cable files by default

Issue

Closes #30794

Additional Information

Tested on a fresh Rails 8.1.2 install. Confirmed app/channels/ does not exist after rails new and is properly created after rails generate channel message.

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@github-actions github-actions bot added the Content: Ruby on Rails Involves the Ruby on Rails course label Mar 18, 2026
@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 18, 2026

@JoshDevHub could you please review this PR? Welcome to any feedbacks.
thank you

@mao-sz
Copy link
Copy Markdown
Contributor

mao-sz commented Mar 18, 2026

@bittoby Please do not ping specific maints for review, especially so soon after opening the PR. We are all volunteers with our own schedules. One of us will eventually get to reviewing this, whether it's Josh or another maintainer.

Let's now deal with setting up the server connection. As we covered in the Action Cable lesson, the connection manages all the channels that a client subscribes to and deals with authentication and authorization.

If you open up `app/channels/application_cable/connection.rb` we can authorise a connection when the user logs in. The code is pretty identical to the [connection](https://guides.rubyonrails.org/action_cable_overview.html#server-side-components-connections) found in the Rails Guides on Action Cable, with the only difference being we can use the user details set on the warden object environment variable.
In Rails 8, the Action Cable files are not generated by default when you create a new app. We need to generate a channel first, which will also create the necessary Action Cable directory and files. Let's create a channel for messages. In the terminal we can write
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails 8 has been out for a while now, so we need to specify that this is Rails 8 behaviour. I doubt any learners are still on rails 7. Maybe we could just start with "We need to generate a channel first"

Copy link
Copy Markdown
Contributor Author

@bittoby bittoby Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback! Fixed


This has created the Action Cable base files (`connection.rb` and `channel.rb`), as well as the `message_channel.rb` and `message_channel.js` files we will use shortly.

Now open up `app/channels/application_cable/connection.rb` so we can authorize a connection when the user logs in. The code is pretty identical to the [connection](https://guides.rubyonrails.org/action_cable_overview.html#server-side-components-connections) found in the Rails Guides on Action Cable, with the only difference being we can use the user details set on the warden object environment variable.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will users be familiar with warden?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@XAJX179
Copy link
Copy Markdown
Contributor

XAJX179 commented Mar 18, 2026

@bittoby Please do not ping specific maints for review, especially so soon after opening the PR. We are all volunteers with our own schedules. One of us will eventually get to reviewing this, whether it's Josh or another maintainer.

hello @mao-sz & @CouchofTomato ,
@statxc was already assigned by josh on this issue as he was the first one to comment #30794 (comment) (on feb 13) on this issue i created. just wanted to share that this PR was created for an issue which has someone else assigned #30794 (comment) (20 hours ago only)

@statxc
Copy link
Copy Markdown
Contributor

statxc commented Mar 18, 2026

Go ahead, @bittoby. I’m working on another issue now, so it’s fine with me.

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 18, 2026

Go ahead, @bittoby. I’m working on another issue now, so it’s fine with me.

Thanks @statxc 👍

@mao-sz
Copy link
Copy Markdown
Contributor

mao-sz commented Mar 18, 2026

Good spot @XAJX179, I didn't notice. I'll let Tomato decide what to do with this PR.

@bittoby we have a very clear workflow in place as per our contributing guide, which you ticked the box saying you've read.
When there is an assignment system in place, it is bad etiquette to step over people with your own work. Many teams will simply reject the PR and it wastes everyone's time.

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 18, 2026

Good spot @XAJX179, I didn't notice. I'll let Tomato decide what to do with this PR.

@bittoby we have a very clear workflow in place as per our contributing guide, which you ticked the box saying you've read. When there is an assignment system in place, it is bad etiquette to step over people with your own work. Many teams will simply reject the PR and it wastes everyone's time.

Ah, thanks for letting me know. By mistaken, I missed that point. Really sorry. I’ll be more careful in the future.
But for this issue, @statxc already agreed that I’m working on it. If possible, I’d like to complete this task. I’ll be more careful going forward. 🙏

@bittoby bittoby requested a review from CouchofTomato March 18, 2026 15:05
@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Mar 21, 2026

I’d appreciate any feedback from anyone.

@CouchofTomato CouchofTomato merged commit 08d025d into TheOdinProject:main Mar 23, 2026
3 checks passed
@bittoby bittoby deleted the fix/actioncable-missing-channels-rails-8 branch March 23, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content: Ruby on Rails Involves the Ruby on Rails course

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Websockets and Actioncable : rails new does not automatically generate app/channels directory.

5 participants