简体   繁体   中英

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!

There is a Rails helper, mail_to out there that is designed to do exactly this...

Read more from here. http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-mail_to

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM