Go to particular div in rails 3 - html

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.

Related

Remove <a> tag from rails "link_to" methdo

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') %>

Anchor tags with rails 4 working weird

Ok so I've encountered a very very weird problem that has got me staying up late but I finally figured out whats wrong however, the solution is not ideal and I would like to know what is happening. Better yet, how to fix it.
I have a page seperated with many div tags with the id class. I have other pages that are done the same way with no problems at all when I try to link to a particular section of a page from another page with the following methods. However, the problem occurs when the page Im linking to has not enough content.. but still is at least scrollable length.. When clicking on the links that way, instead of moving to the desired section, it just moves towards the bottom.
For instance if you clicked on this website, http://aquaticshelp.com/aquascape/getting-started#aquascape-main-plants and clicked on the "Preparing your plant section" you will see what I mean. This is a very undesirable behavior and Im not sure where to go from here.
<%= link_to 'Section 1', route_path(anchor: "section-1"), class: "h4" %>
<div id="section-1">
</div>
<div id="section-2">
</div>
<div id="section-3">
</div>
EDIT: Added some screen shots for clarity of question
Below is where you click and contains the following code
<%= link_to aquascape_plants_prep_path(anchor: "aquascape-plants-prep-intro") do %>
<%= image_tag("aquascaping/start/plant_prep_img.jpg", size:"140x140", class: "img-circle center-block")%>
<%= link_to 'Preparing the Plants', aquascape_plants_prep_path(anchor: "aquascape-plants-prep-intro"), class: "h4" %>
<% end %>
The following is where it directs me to regardless of the anchor tag
Where I want it to go, and it does if I click on the following
<%= link_to 'Intro', "#aquascape-plants-prep-intro" %>

Creating a clickable div with 'link_to' syntax

I have a clickable div but instead of using the full address for the link, I'd like to use ruby's 'link_to' syntax. How would I point to "facebook_path" instead of the full address?
<div id="item_1", onclick="location.href='http://www.facebook.com';" style="cursor:pointer;"> Home </div>
You can do that using the following syntax:
<%= link_to "http://www.facebook.com", id:"item_1" do %>
#your code here
<% end %>
I hope this is what you were looking for
I'll assume you are just using erb, but you can pass a block to the link_to helper. So your example would be:
<%= link_to 'http://www.facebook.com' do %>
<div id="item_1" style="cursor:pointer;">
Home
</div>
<% end %>
In light of your comments, let me explain the difference between css and rails (which is what your issue is):
You can create an a block by using the following code:
<%= link_to your_path_helper, class: "class", id: "id" do %>
Stuff here
<% end %>
This will render the following HTML:
Stuff here
The question you have now is "how do I make this style the same as another element (div or similar)". The way to do this is to use css:
#app/assets/stylesheets.css
a.id {
color: #000; /* makes the link color black */
text-decoration: none; /* Removed underline */
}
CSS works by styling the different elements of your page. The class and id selectors allows you to identify the specific items, whilst the css properties help you pick the right styling
Your issue is you're trying to style your a element in the same way as your div. You need to select the a element & style that in your CSS

Create html anchor in rails

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") %>

How to create a link without href attribute on rails 3 with link_to?

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 %>