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
13
votes
4 answers

call javascript function from haml link_to

I would like to invoke a javascript function (without JQuery) when the onclick even fires from a link_to tag in haml. How can I do this?
Sandah Aung
  • 6,156
  • 15
  • 56
  • 98
13
votes
2 answers

Submit form using link_to in rails

I'm trying to submit a form using link_to as follows: <%= form_for(@post, :url=> '/post/action', :method=> 'post', :html => {:id=>'form_id'} ) do |f| %> .... <%= link_to 'submit', "/post/action",…
random
  • 10,238
  • 8
  • 57
  • 101
12
votes
1 answer

rails 3 render partial with params

I'm having a problem passing some parameters to a partial. No matter what I've tried the params don't pass when the partial is rendered. I am using a jquery tabbed layout, and each tab displays work orders in a particular status and also based on a…
user1214966
  • 273
  • 1
  • 4
  • 10
12
votes
4 answers

Ruby on Rails: How to pass parameters from view to controller with link_to without parameters showing up in URL

I am currently using a link_to helper in View to pass parameters like title , author ,image_url and isbn back to controller <%= link_to 'Sell this item',new_item_path(:title => title, :author => authors, :image_url=>image, :image_url_s=>image_s,…
user1994764
  • 15,889
  • 5
  • 19
  • 11
12
votes
3 answers

Rails :confirm modifier callback?

I want to call a javascript function that will be conditional upon a user's response to the confirm box. For example, I have the following anchor: <%= link_to 'Sign Out', destroy_session_path, confirm: 'Are you sure that you would like to sign…
11
votes
4 answers

rails 3 link_to with nested content_tag to create

Hi I got a noob question, I want to create the following HTML result: TEXT In the above HTML I want to have text with a span-class to style in an image via…
user1260945
  • 111
  • 1
  • 1
  • 3
11
votes
1 answer

problems with form_tag for controller action with members-get route

I'm making a form_tag panel that contains information (checkboxes) specific to a controller action. This action is set up in "routes.rb" as follows: resources :students do collection do get :send_student_report_pdf end end This setup…
Dominic
  • 341
  • 2
  • 5
  • 15
11
votes
5 answers

How to use the link_to helper to open a popup?

I just want to use link_to to open a popup. I tried something but it doesn't work: <%= link_to 'Create a new company', new_company_path, :popup => ['create_company', 'height=600, width=600'] %>
Any idea? Thanks!
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
11
votes
4 answers

How do I add a span in a link_to with an image

So I have this: <%= link_to(image_tag(@model.picture.url(:thumb), :alt => ''), "/pages/you/#{something.id}", {:id => "y_link_#{something.id}"}) %> Which works, but I need a span in between also like this:
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321
11
votes
2 answers

Specifying a :format in link_to doesn't work in rails 3.2.2

I'm moving a project from rails 3.1 to rails 3.2.2 and I have this: = link_to 'CSV', :action => 'list', :search => @search, :format => 'csv' In rails 3.1 this specifies the format in the html link (format=csv) and it is caught by a respond_with,…
cbron
  • 4,036
  • 3
  • 33
  • 40
10
votes
5 answers

Rails: "new or edit" path helper?

Is there a simple and straightforward way to provide a link in a view to either create a resource if it doesn't exist or edit the existing on if it does? IE: User has_one :profile Currently I would be doing something like... -if…
Andrew
  • 42,517
  • 51
  • 181
  • 281
10
votes
4 answers

Rails 3 - Javascript :confirm not working for link_to and button_to with :method => :delete

In my index.html.erb file I'm trying to display the title to my object (a "listing") and the normal "show", "edit", and "destroy" links and/or buttons. With :method => :delete and :confirm => "are you sure?", neither link_to or button_to will…
Don Leatham
  • 2,694
  • 4
  • 29
  • 41
10
votes
3 answers

SEO/Rails - How to add the title tag to every "link_to"

I'm surprised Rails creator didn't think about that, if someone can help, would be great. How can we do to change this: <%= link_to "My Title", :controller => "products" %> to this automatically: <%= link_to "My Title", :controller => "products",…
Alextoul
  • 839
  • 3
  • 9
  • 19
10
votes
2 answers

clean way to make the "confirm" conditional in rails 4

I have a link_to on my rails4 page which uses slim syntax. The following link_to link_to exports_path, data: { confirm: "Are you sure?" } is now required to only show the confirm message upon a certain condition. How do we make this happen in…
Swaroop
  • 431
  • 5
  • 15
9
votes
3 answers

Ruby on rails link_to syntax

After following a tutorial Ive found. Im now redoing it again, without the scaffolding part, to learn it better. However, editing my \app\views\home\index.html.erb to contain:

Rails test project

<%= link_to "my blog", posts_path> I get an…
Mizipzor
  • 51,151
  • 22
  • 97
  • 138
1 2
3
57 58