Files
once-campfire/app/controllers/rooms/opens_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

50 lines
1.2 KiB
Ruby

class Rooms::OpensController < RoomsController
before_action :set_room, only: %i[ show edit update ]
before_action :ensure_can_administer, only: %i[ update ]
before_action :remember_last_room_visited, only: :show
before_action :force_room_type, only: %i[ edit update ]
DEFAULT_ROOM_NAME = "New room"
def show
redirect_to room_url(@room)
end
def new
@room = Rooms::Open.new(name: DEFAULT_ROOM_NAME)
@users = User.active.ordered
end
def create
room = Rooms::Open.create_for(room_params, users: Current.user)
broadcast_create_room(room)
redirect_to room_url(room)
end
def edit
@users = User.active.ordered
end
def update
@room.update! room_params
broadcast_update_room
redirect_to room_url(@room)
end
private
# Allows us to edit a closed room and turn it into an open one on saving.
def force_room_type
@room = @room.becomes!(Rooms::Open)
end
def broadcast_create_room(room)
broadcast_prepend_to :rooms, target: :shared_rooms, partial: "users/sidebars/rooms/shared", locals: { room: room }
end
def broadcast_update_room
broadcast_replace_to :rooms, target: [ @room, :list ], partial: "users/sidebars/rooms/shared", locals: { room: @room }
end
end