Link to non http protocol from a Rails mailer template - ios

I'd like to have a link in an email (opened on an iOS devise) open an iOS app.
I have Rails mailer template that contains a link, which opens the app 'myapp' on an iOS device:
<%= link_to 'Reset my password', "myapp://?password_reset_token=#{#token}" %>
This link is rendered properly when used in a regular view, displayed in a browser.
The problem is when the link is used in a mailer template it displays without the href:
<a href>Reset My password</a>
I get the same results when I put the <a> tag manually in the template instead of using link_to. Still results in blank href.
It seems that using any protocol other than http or https yields the same results.
Is there any way to make this non http link display properly

The way I got around this was to adjust my url like this:
"myapp://myapp.com?password_reset_token=#{#token}"
The addition of the 'myapp.com' part made it work, and I can just ignore that part, and parse out the query params that I need.

Above solution do not work as
when I check mail in gmail the href remove from mail, it looks like <a href>Reset My password</a>
So I have done a workaround for it
I have redirected to a route and in that I embed script as below
<script>
$(function(){
window.location = "myapp://myapp.com"+window.location.search
})()
</script>
so it will redirects with all parameters to the URI

Related

if i use querystring on a page navigateurl redirecting in a samepage

I am trying to click on a link in products.aspx and redirect to another page categories.aspx. When i use {*id} in routing to handle querystring on products.aspx link is not working well. Sending same products.aspx page.
My Routes:
routes.MapPageRoute("productsgroup", "products/{groupname}/{*id}", "~/products.aspx");
routes.MapPageRoute("productscat", "products/brand/{bname}", "~/categories.aspx");
Hyperlink in products.aspx page:
<asp:Hyperlink ID="hyper_link" runat="server" NavigateUrl='<% GetRouteUrl("productscat", new {bname=Eval("brand-name").ToString()})%>' Text="Category1"></asp:Hyperlink>
Hyperlink is in a asp:Repeater and Eval() is working fine on a link and link is seems normal, when i click on the hyperlink, url changes but not sending categories.aspx page.
If i delete querystring {*id} and not use than hyperlink works fine.
I am trying to understand why it's happening and what we can do about it.
There is a simple solution. Change route order and your target url and link will work.
routes.MapPageRoute("productscat", "products/brand/{bname}", "~/categories.aspx");
routes.MapPageRoute("productsgroup", "products/{groupname}/{*id}", "~/products.aspx");
Routing thinks target url is "productsgroup" because it knows the url and target url starts like that. Routing waits for the variable and second route like it doesn't exist for routing.
I hope it helps. Cheers.

Create Link to External Website

I am trying to create an external link to each individual listing's assigned website address. Using the following code: (The listing website is saved as google.com)
External Link
Takes me to:
localhost:3000/google.com
Is there any way to generate a link that would go to www.google.com instead of trying to find a route in my application.
The reason why it's bringing you to localhost:3000/google.com it's probably because the string you are passing to the href attribute is not a full qualified URL.
In fact, if in HTML you write
External Link
The string will be appended to the current page path. You should make sure that the input you pass always contains the schema. If the input never contains that, then you can assume it's http://
External Link
But this is not really a solution, just a workaround. You should definitely make sure that when you populate the website URL, you store a complete URL. In fact, some sites may require https.
In Rails you normally use the url_for and link_to helpers to generate an URL, but they will both cause the same issue unless you pass a full URL.
<%= link_to "External Link", "http://#{listing.website}" %>
Do it the Rails way:
<%= link_to 'External Link', "http://#{listing.website}" %>
You need to put in the protocol.
Google
Do you get it? =)
You can create link like this:
External Link

How to use native anchor links with angularjs

I'm using angularjs on a rather large flat documentation page. The page has some navigation thats designed to use traditional url hash links. The urls look like so:
/documentation/flat#26166276-basic-events
These urls get rewritten once the navigation occurs and i've hit the next page. angular initializes to something like:
/documentation/flat#/26166276-basic-events
This breaks the navigation. It seems to work if I am already on the /documentation/flat path and hit one of the hash urls. It gets rewritten but the browser still focus's on the correct section of the page.
However if the the hash url is triggered from a different path the browser will not focus on the correct DOM element as the angularjs rewrite happens.
Edit: this is what the markup for a link looks like
Basic Events
<h1 class="chap-header" id="26166276-basic-events">2.1.0 Basic Events</h1>
This topic was further discussed here:
How to handle anchor hash linking in AngularJS
I used a variation from that thread
if $location.$$url[0]== '#'
$location.hash($location.$$url.replace('#', ''))
$anchorScroll()
that basically lets me prefix any anchor links with an additional # and angularjs treats them as traditional anchor
There is a very silly solution: put a / at the start of the anchor id!
<a id='/my-id' />

Why is my external link rendered as internal link?

I have a form that let people enter various links on my website like: http, https and ftp. When someone enters "http:stackoverflow.com", "https:stackoverflow.com" and "ftp:stackoverflow.com" and renders these in a view like this:
<ul>
#foreach (var link in Model.Keyword.References)
{
<li>
#link.Link
</li>
}
</ul>
I get the following output:
http:stackoverflow.com
https:stackoverflow.com
ftp:stackoverflow.com
This looks fine but when I hover "http:stackoverflow.com" the real link is: "localhost:1973/stackoverflow.com".
When I hover the https and ftp links I get the correct output:
https://stackoverflow.com
ftp://stackoverflow.com
I found out that the http links requires two "forward slashes" when I submit them via a form. So instead of "http:" you get "http://". I would like to know why https and ftp links do not need these extra slashes. I would also like to know a good solution for this because I don't think I should force an user to use these extra slashes.
The slashes in the URL are always required. It could be that your browser does some correction to the invalid url. Try to put https:stackoverflow.com in the addressbar of your browser and it will try to correct it in most browsers.
As for a good solution, I think you should only accept the domain without http://. You can put some small text underneath the input that shows "Example: 'www.somedomain.com'", so that the user knows the protocol in the front is not needed.
You can then use JQUERY/REGEX to validate and trim off any protocol stuff someone might add mistakingly.

Ruby/Rails - Open a URL From The Controller In New Window

I'm in my applications controller and I have a url string. How do I tell the app to open the url in the browser in a new window. Is there a way to set the target to blank?
For example
def link
#url = 'www.google.com'
****??? Open #url ?? *** with target blank?
end
This is not possible to do directly from the controller. Using redirect_to #url has the effect of opening an URL in the same "window", as it simply sends a HTTP redirect instruction back to the browser. redirect_to is not capable of opening new windows. The controller resides on the server side, and opening a new window belongs to the client side.
Some options:
a) render a link with <%= link_to 'Google', 'google.com', :target => '_blank' %> or Google which the user can click on in a new view
b) use JavaScript to open the link automatically, but beware that browsers may treat this as a popup and block it
By combining these options you can open links in new window for browsers/users who allow it, and fall back to a regular URL in case that didn't work.
As the others point out, you can't (and shouldn't) do this in the controller. In the view you can use
<%= link_to #url, :target => "_blank" %>
Well, it's not that you CAN'T do it, it's just kind of a convoluted process. I did this in a project I'm working on. Basically, it's a mixture of Rails goodness and Javascript. I simply passed a flash notice on creation of an instance, and then used a script to set that flash notice equal to a js variable, and a redirect_url. If that particular flash notice pops up on that page, it redirects in the js script. Like I said, it's hack hack hack, but it works for my purposes.
You can't do that in rails, because your script is being executed on a server.
Use Javascript to work with browser on the client side.

Resources