How can I put link_to redirecting to root_path in this HAML code?
.icon-bar.large.vertical.four-up
%a.item
%img{:src => "/svgs/fi-home.svg"}/
%label Home
A quick google search lead me to this, https://rivalfox.com/blog/haml-best-practices/
So I would give the following a try,
= link_to root_path, class: ['btn', 'btn-default'] do
= image_tag 'fi-home.svg'
Home
.icon-bar.large.vertical.four-up
= link_to root_path, class: ['item'] do
= image_tag "/svgs/fi-home.svg"
%label Home
This works, thanks for help.
Related
i want to show an small icon instead of a textlink.
using this piece of code:
<li>
<%= link_to '', :class => 'nav-icon' do %>
<span class="icon-home">Home</span><%= root_path %>
<% end %>
</li>
but rails now shows me the icon followed by a /
is there any way to avoid that behavior?
<li>
<%= link_to root_path, :class => 'nav-icon' do %>
<span class="icon-home">Home</span>
<% end %>
</li>
The / displayed after your icon is generated by <%= root_path %>.
<%= %> seems:
please ruby, write this on my html.
so ruby wrote your root_path variable, and your root_path is equal to /.
remove your <%= root_path %> after <span class="icon-home">Home</span> and everything will be ok.
Following should work
<li>
<%= link_to '', :class => 'nav-icon' do %>
<span class="icon-home">Home</span>
<% end %>
</li>
Reason: the / is coming due to this code <%= root_path %>
and writing just <%= link_to '', :class => 'nav-icon' do %> will create link with empty href
I think you should give your path in the first argument of link_to as follows
link_to(url, html_options = {}) do
# your icon code
end
I'm trying to link to an external page in Rails. I've seen several questions about this but none of the solutions are working for me.
I believe this is because the url is a subdomain (i.e. http://pages.foo.com/contact.html). This link is directing to http://www.foo.com/#!http://pages.foo.com/contact.html instead.
My link_to looks like this:
<%= link_to 'contact', 'http://pages.foo.com/contact.html', :class => 'contact pNav' %>
Any help greatly appreciated. Thanks!
According to rails apidock
<%= link_to 'contact', 'http://pages.foo.com/contact.html', :class => 'contact pNav', :target => "_blank" %>
At the top of the user's profile I have this button:
<%= button_to 'Make a detailed enquiry', user_path(#user), :class=>"enquirySection", :method => :get %>
Then at the very bottom of the page I am rendering a form in which the viewer can make an enquiry:
<div class="enquirySection">
<%= render "enquiries/form" %>
</div>
I want the user to be scrolled down to this form when (s)he clicks on the button so I added the ":class=>"enquirySection"" and "div class="enquirySection"". It doesn't work.
I tried something similar to that but I think it does not related to my case.
Any clue of how is this done in Rails with button_to?
Thank you.
You don't need a class, but an id
try
<%= button_to 'Make a detailed enquiry', user_path(#user, anchor: :enquirySection), :method => :get %>
or simply
<%= link_to 'Make a detailed enquiry', user_path(#user, anchor: 'enquirySection) %>
and then
<div id="enquirySection">
<%= render "enquiries/form" %>
</div>
would do the job.
I'm using Bootstrap 3 and I can do most links, but have problems when the "link_to" function is contained in something else.
These work
<li><%= link_to "Contact", contact_path %></li>
<li><%= link_to "Sign Up", register_path %></li>
I don't know how to use "link_to" for these
<a class="navbar-brand" href="#">Project</a>
Where the path for project is root_path
Resources<b class="caret"></b>
Where the path for resources is resources_path
You can do this:
<%= link_to "Project", root_path , class: 'navbar-brand' %>
<%= link_to resources_path, class: 'dropdown-toggle', data: {toggle:'dropdown'} do %>
Resources <b class="caret"></b>
<% end %>
You don't have to use the link_to helper in cases it isn't actually helpful for you, but you can easily create the desired links using the helper like so:
link_to 'Project', '#', class: 'navbar-brand'
link_to '#', class: 'dropdown-toggle', data: { toggle: 'dropdown' } do
Resources <b class="caret"></b>
end
I'm using Spree as an eCommerce solution for a website that I am building and need to customize the layout, the deface option is great but I already have a layout for the rest of my application that I want to use so there is no change between the main part of my site and the store.
Having looked through the spree source code I have been able to transfer most of the infrastructure over to my own new template but I have hit one stumbling block. In the default template above the search box there are login/account and logout links which based on some digging through the code is rendered in the 'header' partial which itself renders the nav bar which renders the search bar partial, and the main nav bar which shows the links to home and the shopping cart, but nowhere mentions the user in/out stuff. Commenting out the rendering of the header partial removes all of this stuff but also the user information, which as far as I can tell isn't mentioned anywhere...
Does anyone know where in the default spree layout it implements this code for showing a login/logout account link, I could do this relatively simply with basic links to it but would rather understand how Spree implements this itself and I'm trying to keep my layout compatible with any updates to the core code.
Any help would be greatly appreciated, thanks!
Edited: For clarity
On version 3.0.1 of Spree and maybe on other older versions the user functionality is not handled by the core itself. Users are handled by the Spree Auth (Devise) Spree extension. This extension is included by default on new Spree apps. The extension uses a deface override to add this functionality. Interestingly enough the partial used by this override is not on the extension itself but rather on the Spree frontend files. I assume to make this component reusable should you wish to implement your custom user module. This is the code of the partial:
<% if spree_current_user %>
<li><%= link_to Spree.t(:my_account), spree.account_path %></li>
<li><%= link_to Spree.t(:logout), spree.logout_path %></li>
<% else %>
<li id="link-to-login"><%= link_to Spree.t(:login), spree.login_path %></li>
<% end %>
Found code in the RDR theme that explains this, still not sure why it doesn't show up in the default spree code, maybe a data hook?
The way RDR does it:
<% if current_user %>
<%= link_to t('logout'), destroy_user_session_path, :class => "cart" %>
<%= link_to t('my_account'), account_path, :class => "cart" %>
<% else %>
<%= link_to t('log_in'), login_path, :class => "cart" %>
<% end %>
override menu with
<% if current_user %>
<%= link_to t(:logout), spree.destroy_user_session_path %>
<%= link_to t(:my_account), spree.account_path %>
<% else %>
<%= link_to t(:login), spree.login_path %>
<% end %>
As of Spree 2.3.2 same thing can be done with:
<h2>Your Account</h2>
<ul>
<% if spree_current_user %>
<li><%= link_to t('My Account'), account_path, :class => "cart" %></li>
<% else %>
<li><%= link_to t('Log In'), login_path, :class => "cart" %></li>
<li><%= link_to t('Sign Up'), registration_path, :class => "cart" %></li>
<% end %>
</ul>