I am looking for the practice which is most advisable in terms of coding practice
I have a comment system which for each comment, you can reply to. This leads me to several options on implementing this (presume the backend is already created)
- When the user clicks '
reply
', ajax is fired, getting the appropriate partial (including the authenitcation token, etc) and it inserts that into the appropriate place - I have a hidden form for each comment, and clicking
reply
will just make it visible - I use javascript to generate the form on the fly when the user click reply and insert it to the appropriate div where the reply was clicked
My problems with each is
for 1 - This causes requests, delay and I am not sure ajax is needed here
for 2 - Too many forms on the page.. Imagine thousands of comments so for each comment there will be a form which looks more or less the same
for 3 - I don't know if I can generate the authenticity token on the client
the form should look something like
<form accept-charset="UTF-8" action="comments/3/reply" data-remote="true" method="post">
<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" value="J0/asxkDH....vdlKLOUuQ9/TAxACWnZKdwy+c="></div>
<textarea id="comment" name="comment" class="tae" style="overflow: hidden;"></textarea>
<input name="commit" type="submit" value="Send">
</form>