how can i use mail_to and link_to together in an input text field?

Maker from USA

Maker from USA

When someone puts their email or url in the single input text field. The input will know which action to use whether to email or target blank the url. thanks

Maker of WIP amongst other things.

I’m not sure I fully understand the question. I’m assuming this is for Rails?

So you have a textfield where someone could enter either a URL or email address, and then based on what it is you want to generate the correct link?

You’d need to figure out a conditional that determines whether something is a URL or email address and then render it accordingly.

For example something like:

if @value.contains?(“@“)
mailto @value
to @value

This isn’t perfect because URLs could have @-signs in them, but you can use a method meant to check whether something is a correct URL/email. A simple Google search will return many results.

Maker from USA

yes its for rails and yes i want to generate the correct link! right now i have two separate textfields --> it under one div <div>
<%= mail_to 'email', %>

Maker from USA

<%= link_to 'website', %> </div> . Ah okay I'll look into it. Thanks WIPGod!

Maker from USA

I figured it out :)

👋 Join WIP to participate