Class: Gaggle::ChannelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/gaggle/channels_controller.rb

Direct Known Subclasses

Channels::MessagesController

Instance Method Summary collapse

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/gaggle/channels_controller.rb', line 30

def create
  @channel.assign_attributes(resource_params)

  if @channel.save
    respond_to do |format|
      format.html { redirect_to @channel, notice: "Channel was successfully created." }
      format.json { render json: @channel, status: :created, location: @channel }
    end
  else
    respond_to do |format|
      format.html { render :new }
      format.json { render json: @channel.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject



66
67
68
69
70
71
72
# File 'app/controllers/gaggle/channels_controller.rb', line 66

def destroy
  @channel.destroy
  respond_to do |format|
    format.html { redirect_to root_url, notice: "Channel was successfully destroyed." }
    format.json { render json: "#{@channel.name} was successfully destroyed.", status: :ok }
  end
end

#editObject



46
# File 'app/controllers/gaggle/channels_controller.rb', line 46

def edit; end

#indexObject



21
# File 'app/controllers/gaggle/channels_controller.rb', line 21

def index; end

#newObject



28
# File 'app/controllers/gaggle/channels_controller.rb', line 28

def new; end

#showObject



24
25
26
# File 'app/controllers/gaggle/channels_controller.rb', line 24

def show
  @notification = Current.goose_user&.notifications&.unread&.for_messageable(@channel)&.first
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/gaggle/channels_controller.rb', line 48

def update
  if @channel.update(resource_params)
    respond_to do |format|
      format.html { redirect_to @channel, notice: "Channel was successfully updated." }
      format.json { render json: { name: @channel.name, goose_ids: @channel.goose_ids }, status: :ok }
    end

    Turbo::StreamsChannel.broadcast_update_to "application",
      targets: ".#{dom_id(@channel, :title)}",
      content: @channel.name
  else
    respond_to do |format|
      format.html { render :edit }
      format.json { render json: @channel.errors, status: :unprocessable_entity }
    end
  end
end