I am trying to add a user icon to my header. bootstrap is adding more icons than what my code calls for, what is going on? Thanks in advance!
<ul class="nav pull-right">
<% if user_signed_in? %>
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
<% else %>
<li><%= link_to "", new_user_session_path, class: "icon-user" %></li>
<% end %>
</ul>
http://i.minus.com/i7krj72G9Gmsd.png
i am using the responsive navbar btw.
I don't have the bootstrap icons in my rails project to test this, but see if this works:
<%= link_to raw("<i class='icon-user'></i>"), new_user_session_path %>
You can set padding:15px 15px 15px to padding:0 for .navbar .nav>li>a in your CSS.
Related
In Ruby on Rails(5) how do you make a nav link remain highlighted while on a specific page while still using application.html.erb to hold your navigation links?
For example:
application.html.erb
<nav class="nav">
<li><%= link_to "Home", root_path, :class => 'na' %></li>
<li><%= link_to "Units", units_path, :class => 'ACTIVE' %></li>
</nav>
Maybe something simple like:
<%= link_to 'Units', units_path, class: "#{'active' if controller_name == 'units' && action_name == 'index'}" %>
When I add a link_to to a pre-made bootstrap template it ends up putting the link below the nav-icon. I'm not sure if this is a CSS problem or if my code is wrong.
<li><i class="icon-off icon-white"></i><%= link_to('Logout', destroy_user_session_path, :method => :delete) %></li>
Try this
<%= link_to("<i class='icon-off icon-white'></i> Logout".html_safe, destroy_user_session_path, :method => :delete) %>
Currently I have a header that links the user to his profile through this:
<li><%= link_to '<i class="icon-picture"></i> My Profile'.html_safe, current_user %></li>
I would like to be able to link the current user to his profile by doing something like this:
<li>
<a href="<%= current_user %>">
<div><%= image_tag current_user.avatar (:small) %></div>
<strong>Surge Pedroza</strong><br/>
view my profile page
</a>
</li>
But I do not know how to do it through an <a href="...">. Can someone please help me out?
This would be a better way to accomplish what you want:
<%= link_to current_user do %>
<div><%= image_tag current_user.avatar(:small) %></div>
<strong><%= current_user.full_name %></strong><br/>
view my profile page
<% end %>
link_to .. do is useful for the exact situation you are describing. Check the documentation for more examples.
I actually got it :)
<a href="<%= current_user.id %>">
I was wondering what the syntax is to link to an attribute on the same page
I have a list of dates
<ul>
<% #response.each_pair do |date, movie| %>
<li><%= link_to date_format(date), date, :class => 'scroll_to' %></li>
<% end %>
</ul>
These then have movies underneath each date like so
<% #response.each_pair do |date, movie| %>
<h3 class="resultTitle fontSize13">Available on <%= date_format(date) %></h3>
<% movie.each do |m| %>
<div class="thumbnail clearfix">
<img class="pull-left" src=<% if m.image_link %> <%= m.image_link %> <% else %> "/assets/noimage.jpg" <% end %>>
<div class="caption pull-right">
<%= link_to m.name, m.title_id, :class => 'resultTitle fontSize11' %>
<p class="bio"><%= m.bio %></p>
<p class="resultTitle">Cast</p>
<p class="bio"><%= m.cast.join(", ") unless m.cast.empty? %></p>
<%= link_to "Remind me", reminders_path(:title_id => m.title_id), :method => :post, :class => 'links button' %>
</div>
</div>
<% end %>
<% end %>
What i would like to achieve is that when a user clicks on a date in the list then it will take them to that date with movies on the same page
My attribute for each date is
"release_date"
Do i need to link to that, maybe a piece of Jquery aswell to scroll down to that date? or would it jump to the date in one step?
Any advice appreciated, I have linked to other pages before but not the same page like this
EDIT
I have tried this but the page just re renders
<li><%= link_to date_format(date), params.merge(:release_date => 'release_date'), :class => 'scroll_to' %></li>
Am i on the right track?
Thanks
All you need is to give your date a unique identifier and link to that in you list. For instance below we give the h3 for each date an id relative to the date object. The browser knows how to handle internal links and will simply jump to the corresponding identifier. Notice how the id of the field you're linking to gets appended to the end of the url when you click on the link.
<ul>
<%- index = 0 %>
<% #response.each_pair do |date, movie| %>
<%- index += 1 %>
<li><%= link_to date_format(date), "##{index}", :class => 'scroll_to' %></li>
<% end %>
</ul>
<%- index = 0 %>
<% #response.each_pair do |date, movie| %>
<%- index += 1 %>
<h3 class="resultTitle fontSize13" id="<%= index %>">Available on <%= date_format(date) %></h3>
<% movie.each do |m| %>
<div class="thumbnail clearfix">
<img class="pull-left" src=<% if m.image_link %> <%= m.image_link %> <% else %> "/assets/noimage.jpg" <% end %>>
<div class="caption pull-right">
<%= link_to m.name, m.title_id, :class => 'resultTitle fontSize11' %>
<p class="bio"><%= m.bio %></p>
<p class="resultTitle">Cast</p>
<p class="bio"><%= m.cast.join(", ") unless m.cast.empty? %></p>
<%= link_to "Remind me", reminders_path(:title_id => m.title_id), :method => :post, :class => 'links button' %>
</div>
</div>
<% end %>
<% end %>
For the added JQuery transition you can replace
<li><%= link_to date_format(date), "##{index}", :class => 'scroll_to' %></li>
with
<li><%= link_to_function date_format(date), "$('html, body').animate({scrollTop:$('##{index}').offset().top }, 'slow');", :class => 'scroll_to'%></li>
The above isn't exactly a DRY approach, but the important thing to abstract out of that is that you're linking to a unique ID elsewhere on the page and not the code itself.
I'm trying to use one of the icons in Bootstrap for a link_to.
These don't work::
<% link_to '<i class="icon-pencil"></i>', task_path(task)%>
<% link_to task_path(task), html_options = {:class => 'icon-pencil'} %>
I would appreciate the help!
You can use this other form of the link_to helper:
<%= link_to task_path(task) do %>
<i class="icon-pencil"></i>
<% end %>
Make sure to include the = sign before the link_to call.