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
7
votes
1 answer

Rails 3.1.3 using anchor attribute with link_to tag from posts/index to posts/show/id not working

I am using a link_to tag on my posts/index view and want to link it to my posts/show/id view with an anchor that makes it scroll down to the comments form. For some reason I can't get the anchor to work. Here is my code: In posts/index <%= link_to…
kwyoung11
  • 968
  • 1
  • 10
  • 31
7
votes
1 answer

Symfony output only template--without adding to layout.php

Is there any way to disable the addition of layout.php to my actionNameSuccess.php? I would like this setting to be enabled for some modules and disabled(i.e. let layout.php add up) for other modules. I can solve the problem by making a new…
prongs
  • 9,422
  • 21
  • 67
  • 105
7
votes
4 answers

Every link_to on my rails 4 application is being called twice

I'm experiencing some unusual behaviour with my Rails 4 Application. Every single-time I click on a link_to inside my views, my controllers actions are being called twice. For example: In my root_url I have this standard call for users_profile: <%=…
ScieCode
  • 1,706
  • 14
  • 23
7
votes
3 answers

Rails link to file in public folder

I have a file data.txt in the public folder of my Rails project. I want to link to it from one of the pages in my project using link_to. How can I do it? If I do <%= link_to "here", "data.txt" %> it links to domain.com/data.txt instead of…
Paul S.
  • 4,362
  • 10
  • 35
  • 52
7
votes
1 answer

Rails - link_to with custom route

I am new to Rails so please have patience. I wanted to implement "like" on my canteen model, so I created a custom route inside my canteen resource resources :canteens do resources :meals resources :comments match "/like", :to =>…
urSus
  • 12,492
  • 12
  • 69
  • 89
7
votes
2 answers

Rails 3.2 using content_tag to generate a 'Delete' button with twitter-bootstrap icons

I'm trying to replicate the Delete button icon in this example using the Rails 3 content_tag method, within a nested form and using jQuery unobtrusively (or at least I hope to be). Twitter-Bootstrap Delete Button icon (example) The html produced in…
rails3dev
  • 96
  • 1
  • 1
  • 4
6
votes
2 answers

Generate a `link_to` to the controller action `edit`, dynamically

I am using Ruby on Rails 3.0.7 and I would like to generate a link_to to the controller action edit, dynamically. I have to use it in a partial template but the issue is that I am rendering that same partial template for different model data (that…
Backo
  • 18,291
  • 27
  • 103
  • 170
6
votes
1 answer

Rails 5 - in link_to, how to pass a nil (NULL) param?

I have a link where I need to pass a sequence of params, where 2 params are always nill. link_to go_to_action_path(id, par_01, par_02, par_03, par_04) In some cases are the par_01 and par_02 nil, in other par_03 and par_04. If I have these values…
user984621
  • 46,344
  • 73
  • 224
  • 412
6
votes
3 answers

Button_to in Ruby on Rails bad route

I'm trying to use the button_to rails helper. I wrote the following code: <%= button_to 'Edit Item', edit_item_path(@item), :class => 'mark-button' %> and got the following error message No route matches "/items/1/edit" But when I refresh the…
Nachshon Schwartz
  • 15,289
  • 20
  • 59
  • 98
6
votes
1 answer

How do you pass multiple arguments to nested route paths in Rails?

I am new to Rails and normally set up a link_to helper for a normal unnested route like so: link_to "Delete", article_path(article.id), method: :delete, data: {confirm: "Are you sure?"} However I am learning about nested routes and it seems I need…
Cu1ture
  • 1,273
  • 1
  • 14
  • 29
6
votes
1 answer

Ruby on Rails link_to internal id

How do i use a link_to inorder to go to a specific (html) ID on a page normally if i wanted to go to the "whatever_id" on a page i could use
Schneems
  • 14,918
  • 9
  • 57
  • 84
6
votes
2 answers

Rails RESTful Routing With '/' and Slugs

I am looking to do something similar a wordpress slug where I have a URL like this while maintaining RESTful routing: http://foo.com/blog/2009/12/04/article-title The reason I am interested in keep RESTFUL routing is that I am unable to use many…
Eric Lubow
  • 763
  • 2
  • 12
  • 30
6
votes
5 answers

Rails link_to: Do something after confirmation

I'm trying to execute a save action via AJAX using link_to: <%= link_to 'Save', image_path(image), method: :patch, data:{ confirm: 'Save image?', remote: true } %> I want the link to be replaced with Saving... on…
Yarin
  • 173,523
  • 149
  • 402
  • 512
6
votes
5 answers

link_to image_tag with options (rel, title)

In HTML I would write: But I have to adapt it for ruby on…
morg
  • 1,173
  • 4
  • 18
  • 36
6
votes
2 answers

Path from string with parameter

I need a good way to create a set of Rails 3 paths from an array, in the link_to helper. I have: TITLES = ['foo', 'bar', 'baz'] TITLES.each do |t| = link_to t, (.....path....) This way i need to construct a set of…
Leo Burt
  • 109
  • 1
  • 6