Embed hyperlink in ERB

102 views
Skip to first unread message

mike r

unread,
Feb 23, 2017, 10:29:20 AM2/23/17
to Ruby on Rails: Talk
hello all, Im developing a ruby script (ruby 1.8.7)

its a simple script to generate an email using an ERB

my ERB has this 

JIRA ticket:
[ <%= issue_key %> ] - <%= summary %> 




I was wondering if its possible to embed that hyperlink somehow the ERB. When I get the email from this script, it embeds everything as plain text, I cant find a way to embed a hyperlink into a string

similar to this, 

<a href="https://jira-server/etc"> [ ABC-123 ] </a>


Im generating the template like this from my .rb

 templ = File.read('templates/' + template + '.erb')

generate = ERB.new(templ,nil,">").result(binding)


thanks

tamouse pontiki

unread,
Feb 24, 2017, 12:06:24 AM2/24/17
to rubyonra...@googlegroups.com
On Thu, Feb 23, 2017 at 9:28 AM mike r <mike....@gmail.com> wrote:
hello all, Im developing a ruby script (ruby 1.8.7)

its a simple script to generate an email using an ERB

my ERB has this 

JIRA ticket:
[ <%= issue_key %> ] - <%= summary %> 


I was wondering if its possible to embed that hyperlink somehow the ERB. When I get the email from this script, it embeds everything as plain text, I cant find a way to embed a hyperlink into a string

similar to this, 

<a href="https://jira-server/etc"> [ ABC-123 ] </a>

If you want the link text to be the last bit of the issue_key, you can get that by using the built-in File.basename method, and make this your content:

<a href="<%= issue_key %>">[ <%= File.basename(issue_key) %> ]</a>

Note that this is an off-label use of File.basename, but it works since URL paths look just like file paths. I have no recollection of the libraries available in 1.8.7 which has been obsolete for years now, but File.basename was there.

Tamara

Reply all
Reply to author
Forward
0 new messages