How do I go about posting or rendering a message after updating an attribute to reflect the changes? (I couldn't find anything online in respect to this task)
For example: Once a user updates the ticket status there will be a message posted in the comment section reporting "Ticket has been closed". (No flash message, but a permanent one).
tickets_controller.rb
def open
@ticket = Ticket.find(params[:ticket_id])
@ticket.update_attributes(:ticket_status, "closed")
redirect_to ticket_path
end
You need to store the message in database if you want it to persist. Say for ex- There is a ticket raised (Ticket model) and someone closes it. The attribute on backend will update attribute status for ticket model.
def update
tkt = Ticket.where(id: 1)
tkt.update_attributes(status: 1)
end
If this is an ajax call, you can send a response data with message like "Ticket closed " and display it accordingly on html page in the success callback of ajax call. If it's a server call, refresh the page and use the status attribute from Ticket model to create the message.
You can use some enums like
{0 => "Ticket Open", 1 => "Ticket closed", 2 => "Ticket in progress" }
In case messages are not generic and every time some more customization is required, better to create and save the entire message as an attribute in the related model and no need to have enums.