How to use same the form for POST and PUT requests using ejs?

What I'm trying to do is the following:

routes

router.route('/new')
    .get(function (req, res) {
        var method = ''
        res.render('users/new.ejs', { method: method });
    });

router.route('/edit/:user_id')
    .get(function (req, res) {
        var method = '<input type="hidden" name="_method" value="put" />'
        var user = User.findById(req.params.user_id, function (err, user) {
                if(!err) {
                    return user;
                }
            });
        res.render('users/edit.ejs', {
            method: method
        });
    });

_form.ejs

<form accept-charset="UTF-8" action="/api/v1/users" method="post">
    <%- method %>
    <div class="field">
        <label for="firstName">First Name</label><br>
        <input id="firstName" name="firstName" type="text" />
    </div>
    <div class="field">
        <label for="age">Age</label><br>
        <input id="age" name="age" type="number" />
    </div>
    <div class="field">
        <label for="annualIncome">Annual Income</label><br>
        <input id="annualIncome" name="annualIncome" type="number" />
    </div>
    <div class="field">
        <label for="email">Email</label><br>
        <input id="email" name="email" type="text" />
    </div>
    <div class="field">
        <label for="riskTolerance">Risk Tolerance</label><br>
        <input id="riskTolerance" name="riskTolerance" type="number" />
    </div>
    <div class="actions">
        <input type="submit" value="Submit">
    </div>
</form>

So, I want to do it like in Rails where you can use the same form for both creating and editing a model. So, I wanted to say that it is a PUT request when the form is used for editing.

Is this the appropriate way to do it?

Rather than embedding html in your routing code, you could just use a conditional statement in the ejs template

routes

res.render('users/edit.ejs', {
    put: true
});

_form.ejs

<form accept-charset="UTF-8" action="/api/v1/users" method="post">

    <%if (put) { %>
        <input type="hidden" name="_method" value="put" />
    <% } %>

    <div class="field">
        <label for="firstName">First Name</label><br>
        <input id="firstName" name="firstName" type="text" />
    </div>

    ...

</form>