Birds-Eye.Net
All things broadband and more...
 
Web Birds-Eye.Net

What's New?

Ruby on Rails (RoR)
Programming Reference


Models
External database connections
Passing current_user into model
Passing object into model
Using static lookup tables
Validates IF
Validates MongoMapper

Views
Dynamically delete form element
Edit create nested data
HTML form field check_box
Layout jQuery datatable module
Select array
Select cascading via JS
Text_area Array
Text_area listing submit
Text field format time

Controllers
Dynamic model selection
Including first item from a sorted desc table
Using from_unixtime on epoch dates

Rack
Integrated NTLM/Kerberos Authentication
Pass-through Authentication w/ NTLM

ActionMailer
Broken links in emails

Rails General
Add, Subtract, Multiply, and Divide
Calculate number of weekdays for date range
Date->Epoch & Epoch->Date
Extract first letter of each word
Hash of hashes assignment
Using: variable as hash index

jQuery
jQuery accordion MongoDB


More to come

 

Formatting an HTML link to properly display within an email

By: Bruce Bahlmann - Contributing Author (your feedback is important to us!)

In rails development, when using ActionMailer a problem arises when attempting to programmatically send emails with links back to the rails application that generated them. This post describes how to link back to your hosted application cleanly and easily.

When building your view for generating text of your email, a common mistake is trying to simply use a standard link_to statement to provide a convenient link back to the hosting application.

[app/views/notifier/email_survey.text.erb]
<%= link_to 'Access Survey', responses_path %>

The code above will generate an HTML link within your email message but actual referenced (href) link will look something like the following:

The "applewebdata://0196E10E-4E7E-4664-B72B-A7491C12AF8E/responses" obviously is not a valid link, and if you click on this link within your email, it will go nowhere - chances are it won't even pull up your browser.

The fix for this is pretty simple and does not require any other environment configuration.

[app/views/notifier/email_survey.text.erb]
<%= link_to 'Access Survey', url_for(:controller => "responses", 
                                     :action => "index", :only_path => false) %>

The above simply links to a fixed location, such as an index page. If you want to link to a specific record (i.e. exercise an edit function) using the above method, your code needs to look something like this:

[app/views/notifier/email_survey.text.erb]
<%= link_to 'View Video Log Entry', url_for(:controller => "posts", :action => "edit", 
                                            :id => @entry, :only_path => false) %>

Exercising either of the recommended methods above, should generate a valid link as below:

The link above will correctly trigger your browser to launch and will access the link you specify in your code. Seems like a silly post to explain this, but why this isn't well documented is beyond me.

Can Birds-Eye.Net help you or your Company?
Receive your Birds-Eye.Net articles and white papers hot off the presses by adding our RSS feed to your reader.

 

 

(C) Copyright Birds-Eye.Net, All rights reserved.
It is against the law to reproduce this content or any portion of it in any form without the explicit written permission of Birds-Eye Network Services, LLC. Federal copyright law (17 USC 504) makes it illegal, punishable with fines up to $100,000 per violation plus attorney's fees.