ActionCable lesson: Fix lesson flow for Rails 8 missing channels directory#30913
Conversation
…s app/channels directory
|
@JoshDevHub could you please review this PR? Welcome to any feedbacks. |
|
@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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Will users be familiar with warden?
hello @mao-sz & @CouchofTomato , |
|
Go ahead, @bittoby. I’m working on another issue now, so it’s fine with me. |
|
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. |
Ah, thanks for letting me know. By mistaken, I missed that point. Really sorry. I’ll be more careful in the future. |
|
I’d appreciate any feedback from anyone. |
Because
Rails 8 no longer auto-generates the
app/channels/directory when runningrails new. This causes learners to get stuck when the lesson asks them to openapp/channels/application_cable/connection.rbbecause the file does not exist yet.This PR
actioncable_lesson.mdso thatrails generate channel messageruns before editingconnection.rbactioncable_lesson.mdandwebsockets_and_actioncable.mdto reflect Rails 8 behaviorIssue
Closes #30794
Additional Information
Tested on a fresh Rails 8.1.2 install. Confirmed
app/channels/does not exist afterrails newand is properly created afterrails generate channel message.Pull Request Requirements
location of change: brief description of changeformat, e.g.Intro to HTML and CSS lesson: Fix link textBecausesection summarizes the reason for this PRThis PRsection has a bullet point list describing the changes in this PRIssuesection