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
6
votes
2 answers

Making a conditional link_to statement in Rails?

In the code below, I'm trying to make it so that, if a user has accepted an invite, they'll be able to click on the "not attending" div to decline the invite. That bit of logic works fine, but I'm trying to get it so the "not attending" div shows up…
Adam Templeton
  • 4,467
  • 7
  • 27
  • 39
5
votes
3 answers

Ruby on Rails guide DELETE section not working

<%= link_to "Destroy", article_path(@article), data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %> This is listed on the official website of Ruby on Rails as a simple way of deleting an…
5
votes
1 answer

How to generate a `link_to` URL passing some custom parameters?

I am using Ruby on Rails 3.0.9 and I would like to generate a link_to URL passing some custom parameters. That is, having a articles_path (www.my_web_site_name.com/articles) I would like to generate something like the following: link_to 'Sample link…
Backo
  • 18,291
  • 27
  • 103
  • 170
5
votes
3 answers

Rails: Use URL Helper in Observer

I have an observer which looks like this: class CommentObserver < ActiveRecord::Observer include ActionView::Helpers::UrlHelper def after_create(comment) message = "#{link_to comment.user.full_name, user_path(comment.user)}…
Andrew
  • 42,517
  • 51
  • 181
  • 281
5
votes
2 answers

Rails3 - How to send Javascript Variable to a controller's action with the link_to helper?

If i have the following javascript code var myVar = 0; function setNewValforVar(newValue){ myVar = newValue; } and i'm calling setNewValforVar function n times so when I click on a link it'd send myVar value to the controller action in a…
Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85
5
votes
3 answers

Rails 3 - How to send data on link_to :remote=>true?

I am trying to figure out the new link_to in Rails 3 but i still don't get it In Rails 2 I do: <%= link_to_remote "My Link",:url=>{:action=>:myaction},:with=>"'data='+$('#someField').attr('value')" %> but with the new syntax in Rails 3 how should…
Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85
5
votes
2 answers

Ruby on Rails : Link_to method: :delete does not work

I'm building a feature in Ruby on Rails that allows one to take notes, edit them, and deletes them. I can create no problem, edit no problem, but when i go to delete i get redirected to that notes page and it doesn't get deleted. index.html.erb
user4544501
5
votes
4 answers

How do I create a download link that doesn't blink?

I would like the user to be able to download a file from a method I set up in a controller. Further, I don’t want the URL to change in my browser when the user downloads the file. I have this link set up <%= link_to image_tag("cc_icon.png"),…
user7055375
5
votes
1 answer

Rails: Prevent XSS when using link_to with model attribute given to href

Considering the following link_to example: link_to "Personal Website", @user.website How can I protect it against XSS attack. User table is in an external DB, so I cannot trust it. I have tried different approaches using sanitize and h but when I…
smndiaye
  • 438
  • 7
  • 13
5
votes
3 answers

Rails link_to and audio_tag

I'm trying to figure out the best way to play a wav file in the background (HTML5-like) when I use a link_to tag in Rails. Here's a sample link_to from one of my views: <%= link_to 'At Station', at_station_mdt_index_path, :class => 'btn btn-success…
nulltek
  • 3,247
  • 9
  • 44
  • 94
5
votes
1 answer

rails 4 with link_to and method post with strong parameters

I'm stuck in a problem which can't be that complicated, but I'm just not getting things right. Assuming I've got two Models: class Notification < ActiveRecord::Base belongs_to :device validates :number, presence: true end and class Device <…
4
votes
1 answer

Why is embedded ruby not working in a static page in public folder?

I have a nav button that loads a new page (create.html.erb) through Lightbox 2. create.html.erb is placed in the public folder. Everything loads fine but the embedded ruby doesn't work.
toandang
  • 109
  • 1
  • 3
  • 11
4
votes
2 answers

Rails 3.1 link_to not showing confirmation or destroying properly

I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while. In 10.4.2, Michael Hartl…
flipside
  • 579
  • 6
  • 11
4
votes
3 answers

Rails 3 - Custom link_to helper (with default class and ability to add classes)

I'm trying to hook up a custom helper that has a default class 'pjax' but also retains an ability to add classes where need be. Example: link_to_pjax('pagename', page_path, :class => 'current') So the helper would add the 'pjax' by default, and…
Galaxy
  • 3,370
  • 3
  • 29
  • 41
4
votes
4 answers

symfony link_to in action

I need to give a link in user feedback(via setFlash method). So In my processForm() function, I want to use link_to but that won't work due to symfony's strict MVC policies. I tried manually writing
prongs
  • 9,422
  • 21
  • 67
  • 105