Search code examples
ruby-on-railsrubyerbmailto

Extracting Data from an Id tag (ruby)


I am still learning and been re-searching the topic for couple of hours.

The following code in my views displays the email address in the forum

<form id="user_details" action="<%= request.path %>" method="post" >
<output id="email">
</form>

What I am trying to do is make the email text a hyperlink (just like mailto). I just have no idea what the right syntax for this would be.

Thank you so much!


Solution

  • I read up a bit on the output tag and it is supposed to be the result of a script calculation. It doesn't really fit in with what you are doing here. The output tag is not a form tag so your form won't post the email address in the output tag. However - you are asking for how to show it as a mailto link. You can replace the output tag with an anchor tag instead:

    <a href="" id="email"></a>
    

    then you have to find the script that populates the field with the id email and see to that it also populates the href attribute with mailto:email@example.com. If this is jquery it would be something like:

    var updateEmailTag = function(email) {
        $('#email').html(email);
        $('#email').attr('href', 'mailto:' + email );
    }
    

    If you instead want to do this on the server side you'll have to find where the email comes from and then use the mail_to helper as suggested by Aditya Kapoor.