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

Add anchor option in Rails link_to using array

I'm using an array to generate the path for my rails link_to tags and can't seem to figure out how to add an anchor option. Here are my link_to tags: <%= link_to pluralize(post.comments.count, 'comment'), [post.postable, post] %> <%= link_to "Leave…
krnjn
  • 125
  • 1
  • 3
  • 8
4
votes
2 answers

activeadmin link_to

Hello i have to make some links in the Active Admin admin pages, but i have some problems understanding the hashes to make searches for specific entries, for example: column 'Campaigns' do |advertiser| link_to "#{advertiser.campaigns.count}…
4
votes
2 answers

Ruby on Rails - Passing values to a link_to

I'm a RoR beginner and am using Rails 3.2.3. I have a search form on my page and it performs a get request and filters the results correctly. I want to add the possibility of also searching Products by dates. I inserted a date_select and am able…
Silver
  • 693
  • 1
  • 10
  • 27
3
votes
1 answer

What's the correct way to do ajax callback with Rails 3 link_to

Here's the scenario. Summary: I have a solution, but I want to know if this is the best way to get an AJAX callback working in Rails 3. Problem: I have a link that when clicked it should use AJAX to update an existing html element (in my case a…
haroldcampbell
  • 1,512
  • 1
  • 14
  • 22
3
votes
2 answers

link_to external URL treated as internal despite starting with http:// (Rails 2)

I'm using link_to "Click Here", "http://www.cnn.com" and its producing a link with the following href "localhost:3000http://www.cnn.com" For some reason, it's not recognizing the http:// as indicating an external URL, and treating it as a…
Rick Heller
  • 81
  • 1
  • 3
3
votes
1 answer

Rails 3 - Link to :remote, updating the address URL

I'm currently toying with updating page content via the following: <%= link_to(content_tag(:span, 'Settings'), edit_admin_store_path, :remote => true)%> With the javascript as such: $('nav li a').bind("ajax:success", function(event, data){ …
Galaxy
  • 3,370
  • 3
  • 29
  • 41
3
votes
1 answer

Rails: How to add external link to rails app

I have a string in which users input a URL, which is later displayed in index.html. How can I turn that into a working external link? Right now, the link displays as should (e.g. www.facebook.com/tester), but when I click on the link I get a no…
Tony
  • 981
  • 5
  • 16
  • 30
3
votes
1 answer

RoR Routes Error: From a link_to built URL, route appears in rake routes

routes.rb resources :project_associations, :only => [:update] rake routes project_association PUT /project_associations/:id(.:format) {:action=>"update", :controller=>"project_associations"} ERB <%= link_to membership_command[:text],…
kkelly18
  • 518
  • 1
  • 5
  • 12
3
votes
1 answer

'ActionView::Template::Error - No route matches' passing "old style" parameters for a 'link_to' statement

I am using Ruby on Rails 3.0.9 and I had this problem: Trouble on setting the ':controller' parameter for a 'link_to' statement. No one answered with a solution but, trying and re-trying to find and solve the problem, I have found that on passing…
Backo
  • 18,291
  • 27
  • 103
  • 170
3
votes
2 answers

Rails: set a value using a link

I need help trying to create a link that submits an edit form. Let's say I have a list of objects Object - Color - Own? Ball - Red - false - [button] Hat - Blue - true - [button] Shoe - Green - false - [button] When…
jlarry
  • 430
  • 5
  • 18
3
votes
3 answers

Trouble using 'link_to' and jQuery

I am using Ruby on Rails 3.0.7 and jQuery 1.6.1 and I am binding an AJAX click event to a link_to HTML output as in the following example: link_to 'Link name', '#', :id => 'link_css_id' As you can see I set the URL to '#'. Doing that when I click…
user502052
  • 14,803
  • 30
  • 109
  • 188
3
votes
1 answer

Link_to Routing Issue With Nested Resources

I have two models Jobs and Questions. A job has many questions and questions belong to a job. I've set up the resources in the model, as well as the routes. I am having an issue trying to link_to the Show method of the questions controller on the…
Igrabes
  • 244
  • 4
  • 15
3
votes
1 answer

How to put a link into an h1 with haml in rails?

Hi :) I'm new to haml and want something like this: %h1 =link_to "Home" :root How could I realize this? Hope you can help me with this :)
optikfluffel
  • 2,538
  • 4
  • 20
  • 27
3
votes
1 answer

Rails link_to w/ path AND url_options

How do I set a path and :path_only => false for Rails' link_to method? Our site has a lot of rails-made hyperlinks looking like this: <% link_to "anchor text", "/path/" %> which yields anchor text I have the assignment to…
JellicleCat
  • 28,480
  • 24
  • 109
  • 162
3
votes
1 answer

Use a link_to to set persistent cookie in Ruby on Rails

I would like to save a cookie with a visitor's browser using a link_to or a button. It's sole purpose is display a one time welcome message. application_controller: class ApplicationController < ActionController::Base before_filter…
BasicObject
  • 765
  • 1
  • 5
  • 23