A New Breed of MUSH Server

Modifying the Edit Request

Everything we added so far lets us view our goals on the web portal, but what if we want to edit them too? This requires us to modify another pair of web requests.

Edit Request

The edit request is used when someone wants to edit a character’s profile. It supplies the data for editing, which is subtly different from the data for viewing. In particular, we use a different helper when formatting markdown data for input instead of output. This helper converts %R’s to linebreaks, but leaves ansi codes alone.

The edit request handler lives here: aresmush/plugins/profile/web/profile_edit_request_handler.rb

    rp_hooks: Website.format_input_for_html(char.rp_hooks),
    goals: Website.format_input_for_html(char.goals),

Edit Save Request

There’s a separate request when the user clicks the ‘save’ button on the web portal. It lives here: aresmush/plugins/profile/web/profile_save_request_handler.rb.

This handler does the actual updating of the character data. Our data comes in the request.args variable. We can use yet another helper method to format our input for MUSH. This converts line breaks back into %r’s and does a few other things to make the website entry suitable for storage.

    char.update(rp_hooks: Website.format_input_for_mush(request.args[:rp_hooks]))
    char.update(goals: Website.format_input_for_mush(request.args[:goals]))

This article is part of the Modifying the Web Portal tutorial.