I'm trying to create a link to a specific page section id.
It's something like the bellow html, but I want to use rails instead...
<a id="tips">Useful Tips Section</a>
Visit the Useful Tips Section
How can I specify the "#tips" in the link_to function? Or should I create a specific route? How?
Thanks in advance
You can use
<%= link_to "Visit the Useful Tips Section", action_path(anchor: tips) %>
In routes you can specify the action_path.
As per Rails API docs you should do the above way, please refer this, and find below example :
link_to "Comment wall", profile_path(#profile, anchor: "wall")
# => Comment wall
try using link_to
<%= link_to "Visit the Useful Tips Section","/#tips" %>
assuming you are linking to an id on the same page
<%= link_to('new button', action: 'login' , class: "text-center") %>
created an anchor tag for login.html i.g
new button
and for
new button
use
<%= link_to('new button', controller: 'admin',
action: 'login' , class: "text-center") %>
Related
I need to remove <a> tag from rails link_to method. Here is current code and result:
<%= link_to "ESP", :locale=>'es'%>
<a href="/es/blog/crazy_page">ESP</p>
Here is my desired outcome:
/es/blog/crazy_page
Reason I need this is so I could make "alternate" link tag in header for each language. Can't seem to find this anywhere.
Use url_for method
<%= url_for(:locale => 'es') %>
I have the following in my html.erb file:
<%= image_tag "logo.jpg", :class => "img-responsive", :href =>"http://www.google.com" %>
However, this is not a clickable link. I assumed the :href = > would make it so. Does anyone have any ideas of making your rails image a clickable link? I tried the following logic which I found on another Stack Overflow Post:
<%= link_to image_tag("logo.jpg", :class => "img-responsive"), "http://wwww.google.com" %>
But this makes the image smaller and adds an odd half circle at the bottom of the image. I also cannot add :style or :class working properly.
Anyone have any ideas?
Not sure if this is the best way, but you could just wrap the image tag with regular anchor tags:
<a href="http://www.google.com">
<%= image_tag "logo.jpg", :class => "img-responsive" %>
</a>
The second way is technically the right way to do it, however since its giving you issues could always try this:
<%= link_to 'http://google.com' do %>
<%= image_tag 'logo.jpg', class: 'img-responsive' %>
<% end %>
As for the class/style not adding properly I've always done it as
class: 'this-is-a-class'
and
style: 'padding-left:30px;'
i'm not able to create a link without the href attribute with link_to
<a class="some-class" title="some-title"></a>
i was searching in some documentation but i haven't seen anything related to this problem.
FYI this type of link is provided to have a clickable item with the title attribute and without the classic '#' in the url. i'm open to other solutions to the problem.
Any suggestion?
You should check out the Tag Helper.
This should do the trick:
<%= tag "a", :class => "some_class", :title => "some_title"%>
you can just type it directly in the view
<a class="some-class" title="some-title"></a>
the link_to helper is used to get the baseurl
Each link should have href attribute.
You could set href to # like this:
<%= link_to "#", class: "some-class", title: "some-title" do %>
Whatever
<% end %>
We are upgrading rails from 2.3.5 to 3.2.1. While upgrading we are getting issue with link_to method.We have the following code snippet.
link_to( name, path_options, html_options, *params )
Here name is:
<span class='bmark_link_tag'><img alt="Post this blog to Stumbleupon" src="/images/png/stumble.png" /> Stumbleupon</span>
But while rendering it is directly displaying the above name value instead of displaying image in UI.
Could you please help us on this ASAP.
You can use image_tag in link_to as,
<%= link_to image_tag("images/png/stumble.png", :alt=>"Post this blog to Stumbleupon", :class=>"bmark_link_tag")+"Stumbleupon", your_path %>
I have these two codes lines in subnativation.
<%= link_to "Basic Info", request.request_uri + "#users_details"%>
<%= link_to "Photos", request.request_uri + "#users_photos"%>
==>
/users/1#users_details
/users/1#users_photos
Its not navigating to that particular Div.
PS: users_details and users_photo are Id's of two different div's
#users_details will navigate to <a name='users_details'></a> and #users_photos to <a href='users_photos'></a> somewhere in your HTML.
So put before your users_details div this: <a name='users_details'></a> and enjoy!
Try writing your links in a style that makes it more obvious where you are actually trying to go: something like <%= link_to "Basic Info", users_path(#user, :anchor => 'user_details') %>. This will create a link to the users#show page but also include the anchor to go to any block level element with the id of user_details.