2020-09-11 12:43:27 -04:00
|
|
|
class MessagesController < ActionController::Base
|
2018-02-08 16:02:16 -05:00
|
|
|
before_action :set_message, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
|
|
# GET /messages
|
|
|
|
def index
|
|
|
|
@messages = Message.all
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /messages/1
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /messages/new
|
|
|
|
def new
|
|
|
|
@message = Message.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /messages/1/edit
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /messages
|
|
|
|
def create
|
|
|
|
@message = Message.new(message_params)
|
|
|
|
|
|
|
|
if @message.save
|
|
|
|
redirect_to @message, notice: 'Message was successfully created.'
|
|
|
|
else
|
2021-01-05 21:44:17 -05:00
|
|
|
render :new, status: :unprocessable_entity
|
2018-02-08 16:02:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PATCH/PUT /messages/1
|
|
|
|
def update
|
|
|
|
if @message.update(message_params)
|
|
|
|
redirect_to @message, notice: 'Message was successfully updated.'
|
|
|
|
else
|
2021-01-05 21:44:17 -05:00
|
|
|
render :edit, status: :unprocessable_entity
|
2018-02-08 16:02:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /messages/1
|
|
|
|
def destroy
|
|
|
|
@message.destroy
|
|
|
|
redirect_to messages_url, notice: 'Message was successfully destroyed.'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
def set_message
|
|
|
|
@message = Message.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2020-06-09 13:41:51 -04:00
|
|
|
# Only allow a trusted parameter list through.
|
2018-02-08 16:02:16 -05:00
|
|
|
def message_params
|
|
|
|
params.require(:message).permit(:subject, :content)
|
|
|
|
end
|
|
|
|
end
|