32 lines
634 B
Ruby
32 lines
634 B
Ruby
class RoomsController < ApplicationController
|
|
before_action :set_room, only: %i[ show edit update destroy ]
|
|
def index
|
|
@rooms = policy_scope Room.all
|
|
authorize @rooms
|
|
authorize @new_room = Room.new
|
|
end
|
|
|
|
def create
|
|
authorize @room = Room.build(name: params["room"]["name"])
|
|
@room.save
|
|
end
|
|
|
|
def show
|
|
authorize @room
|
|
@rooms = Room.public_rooms
|
|
@message = Message.new
|
|
@messages = @room.messages
|
|
@new_room = Room.new
|
|
|
|
render "index"
|
|
end
|
|
|
|
private
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_room
|
|
@room = Room.find(params[:id])
|
|
end
|
|
|
|
end
|