Files
once-campfire/app/controllers/rooms_controller.rb
Stanko Krtalić eecdb29332 Upgrade to Rails 8 and Ruby 3.4.5 (#1)
* Bump Ruby to 3.4.5
* Update dependencies
* Adjust for Rails 8 and Ruby 3.5 API changes
* Mark params strings as mutable in prepapration for frozen strings in Ruby 3.5
* Update test for HTML5 sanitizer
    With Rails 7.1 the HTML5 sanitizer became the default, this breakts this test because the old sanitizer used to delete unpermitted nodes, while the new one returns their content
    The final string is safe, but different then it used to be in Rails 7.0
* Remove direct Turbo tesh helpers require & parallelize tests
* Fix Zeitwerk issues with rails extensions
* Update Resque setup for Redis 5+
* Remove unused views
* Remove GID v1 handler
2025-09-02 17:02:41 +02:00

52 lines
1.2 KiB
Ruby

class RoomsController < ApplicationController
before_action :set_room, only: %i[ show destroy ]
before_action :ensure_can_administer, only: %i[ destroy ]
before_action :remember_last_room_visited, only: :show
def index
redirect_to room_url(Current.user.rooms.last)
end
def show
@messages = find_messages
end
def destroy
@room.destroy
broadcast_remove_room
redirect_to root_url
end
private
def set_room
if room = Current.user.rooms.find_by(id: params[:room_id] || params[:id])
@room = room
else
redirect_to root_url, alert: "Room not found or inaccessible"
end
end
def ensure_can_administer
head :forbidden unless Current.user.can_administer?(@room)
end
def find_messages
messages = @room.messages.with_creator
if show_first_message = messages.find_by(id: params[:message_id])
@messages = messages.page_around(show_first_message)
else
@messages = messages.last_page
end
end
def room_params
params.require(:room).permit(:name)
end
def broadcast_remove_room
broadcast_remove_to :rooms, target: [ @room, :list ]
end
end