Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created April 11, 2019 06:35
Show Gist options
  • Save ynonp/712773f8b25ce2e56aba8a8f510b2333 to your computer and use it in GitHub Desktop.
Save ynonp/712773f8b25ce2e56aba8a8f510b2333 to your computer and use it in GitHub Desktop.
rails new feeder --webpack=react --skip-turbolinks
--- Setup
1. Install devise and create a user model
* rails generate devise:install
* rails generate devise User
2. Create a Post model:
./bin/rails g scaffold post user:references text:text color:string
3. Allow users to create Post-s
* modify posts_controller to authenticate user and merge current user
* remove "user" from post form
* change "color" to color input
--- Webpacker
4. Create a Post React component
5. Create a Feed React component which shows a list of Posts
6. Pass data from Rails -> Webpack
* using a content_tag with data attribute
7. Add "from" to query
8. Verify new messages are only shown after reload
Lab: Add "header" to each post
--- Add Active Channel
9. Setup the connection
* https://guides.rubyonrails.org/action_cable_overview.html
* in ApplicationController make sure to add the new cookie
10. Create the channel
* ./bin/rails g channel Feed --no-assets
11. Broadcast notification to the channel when new post is created
12. Setup actioncable client side with:
* yarn add actioncable
13. broadcast from Controller to Channel
* ActionCable.server.broadcast('feed', posts_for_feed)
14. Create the cable in JS:
* window.Cable = ActionCable.createConsumer();
15. Create subscription in JS:
* Cable.subscriptions.create("FeedChannel", { received(data) {} });
Lab: Add notification when ANY user signs in
--- Add image to each post with Active Storage
--- Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment