Quellcode durchsuchen

Iteration F5. Tests with errors.

master
Nils Dittberner vor 9 Jahren
Ursprung
Commit
1dab96524b
3 geänderte Dateien mit 25 neuen und 0 gelöschten Zeilen
  1. +10
    -0
      app/assets/javascripts/channels/products.coffee
  2. +11
    -0
      app/channels/products_channel.rb
  3. +4
    -0
      app/controllers/products_controller.rb

+ 10
- 0
app/assets/javascripts/channels/products.coffee Datei anzeigen

@@ -0,0 +1,10 @@
App.products = App.cable.subscriptions.create "ProductsChannel",
connected: ->
# Called when the subscription is ready for use on the server

disconnected: ->
# Called when the subscription has been terminated by the server

received: (data) ->
# Called when there's incoming data on the websocket for this channel
$('.store #main').html(data.html)

+ 11
- 0
app/channels/products_channel.rb Datei anzeigen

@@ -0,0 +1,11 @@
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
class ProductsChannel < ApplicationCable::Channel
def subscribed
# stream_from "some_channel"
stream_from "products"
end

def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end

+ 4
- 0
app/controllers/products_controller.rb Datei anzeigen

@@ -44,6 +44,10 @@ class ProductsController < ApplicationController
if @product.update(product_params)
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
format.json { render :show, status: :ok, location: @product }

@products = Product.all
ActionCable.server.broadcast 'products',
html: render_to_string('store/index', layout: false)
else
format.html { render :edit }
format.json { render json: @product.errors, status: :unprocessable_entity }


Laden…
Abbrechen
Speichern