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

render :update on Rails 3.1.0 gives me Missing Template update

I'm working with rails 3.1.0 and this is my first application on 3.1.0 I have a remote link: link_to "my link",{:controller=>"my_controller",:action=>"my_action"},:remote=>true and in my_controller I have def my_action @data = Data.all …
Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85
4
votes
1 answer

Rails: method for 'standardizing' url input from users?

I'd like Users in my Rails app to be able to share a link to their personal website in their profile. Simple enough, I have a column called website and a text field they can fill in to make it work. However, when I display this in a view there's a…
Andrew
  • 42,517
  • 51
  • 181
  • 281
4
votes
2 answers

passing a parameter to the link_to method

How do you pass a parameter through the MVC using the link_to method? view: <%= link_to "Remove Tag", remove_tag_issue_path(issue)%> How do I use the link_to method, to utilize the remove_tag action? issues_controller.rb def…
JZ.
  • 21,147
  • 32
  • 115
  • 192
4
votes
2 answers

The better way to pass the foreign_key value to the Rails controller

It's been almost a week since I've began to dig deeper in forms , associations , hashes , symbols... But it seems I cannot solve the puzzle without your help . I am working on a project for displaying different galleries content . The basic idea is…
R Milushev
  • 4,295
  • 3
  • 27
  • 35
4
votes
1 answer

How to add article title to URL using link_to in Rails app?

I am trying to follow answer to question How to get link_to in Rails output an SEO friendly url? but don't get the result. In my Rails 3 app I have: # routes.rb match '/articles/:id/:title' => 'articles#show' resources :articles #…
Andrei
  • 10,918
  • 12
  • 76
  • 110
4
votes
3 answers

How Rails 3 decides which HTTP verb will be used when clicking on a link generated by "link_to"?

I have two links: <%= link_to("Edit", edit_product_path(product.id)) %> <%= link_to("Delete", product, :method => :delete) %> The generated links are: Edit
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
4
votes
1 answer

How to define a link path

I'm trying to figure out how to make an app with Rails 4. I keep getting stuck on basic things and I don't seem to be able to identify principles to use going forward. I have a profile model and a industry model. The associations…
Mel
  • 2,481
  • 26
  • 113
  • 273
4
votes
2 answers

Rails 4 - link_to with confirm in Rails

I'm trying to customize my dialog confirm the link_to in rails 4. But I do not understand why he rides the html as "confirm", and should be "data-confirm"! I've tried a number of ways, and it is always generated "confirm", like this: <%= link_to…
Mateus Vitali
  • 151
  • 1
  • 4
  • 16
4
votes
1 answer

link_to post edit view in rails

Really basic question about link_to that I'm having trouble finding a straight answer to. So I have an index view that simply lists posts according to user email address. <% @post.each do |post| %> <%= link_to…
neanderslob
  • 2,633
  • 6
  • 40
  • 82
4
votes
3 answers

Conditional link_to block in Rails if condition is met

I would like to wrap a conditional link_to around some code that only renders the link if the following condition is met: IF current_user.type == 'Agent'. The content within the condition still needs to be rendered regardless. My current block looks…
Thomas Taylor
  • 864
  • 8
  • 25
4
votes
2 answers

HTML Entities in Rails link_to

How do I insert HTML entities in a rails link_to? For instance ✭ will give you a star character, how do I insert this inside a quote? For example, <%= link_to " ✭ Home", root_path %> Thanks!
user2085143
  • 4,162
  • 7
  • 39
  • 68
4
votes
1 answer

Passing parameter from link_to to controller method

How can I pass subscription.title to my controller method watchsub? How do you then access the variable in watchsub? In my view I have <% @subscriptions.each do |subscription| %> <%= link_to…
user3646037
  • 293
  • 1
  • 6
  • 16
4
votes
1 answer

How to pass hidden parameters in "link_to"

Is there a way to pass parameters with a link_to call without it showing up on the URL? I'm making a simple star-rating system, and I'm basically making each star an image link that passes its value as a parameter to a new rendering of the same…
funkymunky
  • 1,811
  • 3
  • 20
  • 22
4
votes
2 answers

Rails link_to object interpolation with url instead of path

I have two models, say User and Group I know I can access the show action to each object with the different solutions: # PATH link_to user.name, user_path(user) link_to group.name, group_path(group) # URL link_to user.name, user_url(user) link_to…
Augustin Riedinger
  • 20,909
  • 29
  • 133
  • 206
4
votes
5 answers

How should we combine the div with link_to in Rails?

My original intention was to display some text on the image. At the same time, when we click the images, the webpage will be redirected. And I use link_to function with div containing background image. The code is like this: <%= link_to raw('
Rida
  • 133
  • 3
  • 11