Questions tagged [link-to]

link_to is the method in Ruby on Rails that is used to create link tags within views.

link_to is the method in Ruby on Rails that is used to create link tags within views.

e.g., With the appropriate route defined and the profile object with ID=1,

link_to "Profile", @profile

would return the HTML fragment

<a href="/profiles/1">Profile</a>

More details can be found in the Ruby on Rails API documentation.

863 questions
130
votes
2 answers

"render :nothing => true" returns empty plaintext file?

I'm on Rails 2.3.3, and I need to make a link that sends a post request. I have one that looks like this: = link_to('Resend Email', {:controller => 'account', :action => 'resend_confirm_email'}, {:method => :post} ) Which makes the…
user225643
  • 3,601
  • 5
  • 27
  • 22
105
votes
6 answers

Using Rails link_to for links that post

I have a link that I need to submit a post request with. Normally, I'd use jQuery and prevent the link's default behavior and then submit a form to the destination. This seems like something Rails should be able to help me out with. Sure enough, the…
at.
  • 50,922
  • 104
  • 292
  • 461
76
votes
12 answers

How to add confirm message with link_to Ruby on rails

I wanted to add confirmation message on link_to function with Ruby. = link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?' Any ideas why it's not working?
74
votes
5 answers

Embedded HTML in link_to body in Rails

What is the best way to go about getting embedded HTML in the body of a link generated with the link_to method? I basically want the following: This is a link I have been trying to go about this as suggested in…
Ryan
  • 2,460
  • 1
  • 21
  • 22
67
votes
6 answers

file download link in rails

I would like to give visitors the option to download some pdf. I have tried: <%= link_to "abc", "/data/abc.pdf"%> <%= link_to "abc", "/data/abc.pdf", :format => 'pdf' %> and some variations but they don't seem to work. I keep getting No route…
Ionut Hulub
  • 6,180
  • 5
  • 26
  • 55
59
votes
4 answers

How to mixin and call link_to from controller in Rails?

This seems like a noob question, but the simple answer is eluding me. I need to call link_to in an ActionController method to spit out an HTML link. ActionView::Helpers::UrlHelper.link_to calls url_for, but this calls the AV module's version…
tribalvibes
  • 2,097
  • 3
  • 25
  • 30
47
votes
2 answers

rails link_to :remote

I have the following: <%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %> <% end %> which brings up a…
cgiacomi
  • 4,629
  • 6
  • 27
  • 33
46
votes
7 answers

How do I defined a variable link_to to an external URL

On my site a user has a personal profile with a link to his personal external website. The url of the sites I store in a postgresql database under the name website. When I test the result, I always get a url like…
Fawyd
  • 1,435
  • 3
  • 13
  • 19
39
votes
4 answers

Ruby on rails 3 link_to controller and action

I know this is probably a pretty simple concept. I am trying to create a link to a controller and action. For example I have a link in my layout file to update a record when a link is clicked, so I need to be able to link to the controller and…
Jason Yost
  • 4,807
  • 7
  • 42
  • 65
34
votes
4 answers

Adding span tag in Rails link_to

I've looked on SO about how to add a tag but I didn't see an example that placed the where I want using Rails 3 link_to: My span My data I tried something like: <%=…
tvalent2
  • 4,959
  • 10
  • 45
  • 87
34
votes
4 answers

RAILS link_to external site, url is attribute of user table, like: @users.website

I'm working on a website that allows users to create an account. One of the attributes when creating a user is a users personal website. When I try to use the users website like this: <%= link_to @user.site, @user.url %> The url that gets generated…
thedeepfield
  • 6,138
  • 25
  • 72
  • 107
33
votes
8 answers

Rails link_to with inline styling

I must change a link_to tag color without using a CSS class, how can I do? I've tried something such as <%= link_to item.description, {}, {:style=>'color:#FFFFFF;', :class => "css_class"} %> but it doesn't works on ruby 1.9.2 and rails 3.1
Marco
  • 10,283
  • 4
  • 23
  • 22
32
votes
4 answers

adding a class to a link_to is breaking the link

I'm using link_to in RoR 3 When I use it like this, it works fine: <%= link_to "Add to your favorites list",:controller => 'favourite_companies', :action =>'create', :company_id=>"#{@company.id}", …
mtay
  • 1,336
  • 4
  • 20
  • 36
28
votes
3 answers

Ruby on Rails link_to With put Method

I'm new to Rails, and I'm trying to use the link_to helper to create a link that issues a PUT request instead of a GET request. Specifically, I'm trying to create a link that activates a user's account in my app from the admin's panel. I'm using…
maksim
  • 806
  • 2
  • 9
  • 16
25
votes
3 answers

link_to update (without form)

I want a link to update a resource, without using an HTML form. Routes: resources :users do resources :friends end Rake routes: user_friend GET /users/:user_id/friends/:id(.:format){:action=>"show", :controller=>"friends"} PUT…
Joe
  • 1,747
  • 3
  • 17
  • 24
1
2 3
57 58