overtone
overtone

Reputation: 1093

a Href links in ruby

This is pretty straightforward.

I want to make a href link in html point to a site urls thats determined by a ruby variable. So heres what I have:

<% @jobs.each do |job| %>
<% @tempJobUrl = job.url%>
<a href=<%=job.url%></a><%= job.url %>

job is an object which has the variable of url. The url is pretty standard format http://www.google.com and thats what shows up in the table. However when I press the link, it takes me to the page with

%3C/a

on the end.

Any ideas where this is coming from?

Upvotes: 0

Views: 9886

Answers (5)

Tarun Rathi
Tarun Rathi

Reputation: 597

<%= link_to "#{@data[:item_name]}", @data[:link] %>

If you need a hyperlink where you need the name of item along with link, you can do something similar to this.

<%= link_to "Task", Task_Link %>

Upvotes: 0

Bohdan
Bohdan

Reputation: 8408

Why don't you use the helper method?

<% @jobs.each do |job| %>
  <%= link_to job.url, job.url %>
<% end %>

Upvotes: 1

JamesDS
JamesDS

Reputation: 728

I think the simplest solution would be to use the helper method link_to in the following way:

<% @jobs.each do |job| %>
  <%= link_to job.url, job.url %>
<% end %>

The link_to helper is great for forming hyperlinks. All you need to supply is the URL and the anchor text. See the Ruby on Rails documentation for link_to

Upvotes: 0

Rob
Rob

Reputation: 7099

Like @Felix said, use the link_to helper

<% @somevar = job.url %>
<%= link_to "Anchor text", @somevar %>

Upvotes: 0

felix
felix

Reputation: 11542

You should really use link_to Rails helper for this

Upvotes: 2

Related Questions