I am using <%=link_to "Add fund",addFund_item_path(:id=>item.id),:class=>"addfund btn btn-primary"%>" to generate a link to a path in rails.
I want to get only the url (the href) of the path so I can use it in a form. How do i do that?
Just addFund_item_path(:id=>item.id).
So you just want the actual href? I would do this:
<%= content_tag "a", addFund_item_url %>
It won't be a 'link' per se - it will be clickable, but won't go anywhere - but it will show the full href path
Related
I am using Friendly_ID for slugs on my site and it is working...sort of. I can access the routes correctly, but when I follow a link to the page, it still shows the id. For example, I have a link that shows the following:
<%= link_to "X", location_path(#location, :id => "1")
which displayed the url as localhost:3000/locations/1 so I changed the link to:
<%= link_to "X", location_path(#location, :id => "X")
which displays properly (localhost:3000/locations/X) but when you look at the href of the link in after you navigate to its page, it is displayed as <a ... href="/locations/X.X">...</a>.
Why is the link displaying X.X and not simple X?
You don't need to pass id to the location_path. It will be picked up from #location. Drop id from location_path and it should fix the problem.
I ask myself the question does an pdf tag exist in rails 4 which can show
an pdf file very simple?
This solution answers me that i need to give the correct route informations:
<%= link_to 'Help', public_path%>
I already have an pdf file in my project directory app/assets/public/help.pdf
and now i wanna have a link with the simple name "Help" to have on my page.
Third edit:
After a nice first answer nothing changes and i get the same error message from rails. What i have to write in the routes.rb if i wanna use a link for my pdf file. Does anyone know how can i link an PDF from my own directory!?
In my experience with Rails, I've never seen a PDF link tag helper.
What you want, is to use asset_path in combination with link_to
<%= link_to 'Help', asset_path('data/help.pdf') %>
#=> Help
If it needs to be absolute, you could always use asset_url
<%= link_to 'Help', asset_url('data/help.pdf') %>
#=> Help
What I usually do for linking a document that can be public is I put the document in the public folder in rails and then use this for the path:
link_to 'Help', root_path << 'TheTitleOfYourPDF.pdf'
My requirement is to add a link to mail sent from application developed in Ruby On Rails. Clicking that link in mail need to route user to that particular record in the application.
Can someone please help me with this some sample code.
In your view template use _url. E.g.:
<%= link_to 'Edit User', edit_user_url(#user) %>
it will return the complete URL.
You can use a simple link_to method in the mail or you could use a simple anchor tag. The latter you would have to build up.
If you need information on how to build links and paths check the rails guides. This has an example on the first section of the guide.
e.g. <%= link_to 'Patient Record', patient_path(#patient) %>
Besides this you need to provide more information if you want more help.
If you are starting with Ruby On Rails I would recommend looking at the videos on rails cast.
For your email problem you can look at sending-html-email
Also in the email I like to use the link_to helper like this
<%= link_to 'Click Me', something_url(#user.id), %>
I hope that this works. And Happy Coding
font awesome inside link_to helper with haml
how should I do?
i have this code
.link_header
{link_to_ledger(current_ledger) span.icon-flag }
help please
Just pass span as block to link_to helper method something like following:
.link_header
= link_to_ledger(current_ledger) do
span.icon-flag
There are two options for link in rails
As simple
= link_to 'my link text', controllers_path
As you want to do
.link_header
= link_to_ledger(current_ledger) do
%span.icon-flag
-# you can also do what ever you want here even table/images can also be added
I have a Link resource. In my view, I have a series of links that people can click to open another web page:
<%= link_to link.description, "http://#{link.url}", :target => '_blank' %>
If the value of #{link.url} is www.google.com, the link works fine. However, if the value of #{link.url} is http://www.google.com and I click it, it will go to the address http//www.google.com <--- notice it's missing a : after http. Can someone help me remedy this?
Thanks!
How about you add a helper method that checks to see if link.url contains 'http://' or not.
You could use something like this:
def link_formatter(url)
prefix = "http://"
url.include?(prefix)? url : prefix + url
end
That will check to see if link.url contains "http://", if it doesn't it will return the proper format for your url, if it does, it will just return link.url as is.