Im trying to figure out how to make a link in my show page.
I want a link to
<%= #project.external_link %>.
I want to display it as:
<%= link_to '<i class="fa fa-link"></i>' %>
I've tried at least 20 variations on combining these two and I can't find a way that works.
Does anyone know how to display a font awesome icon, with a link to a dynamic field?
Try this:
<%= link_to #project.external_link do %>
<i class="fa fa-link"></i>
<% end %>
Try using :
<i class="fa fa-link"></i>
Related
New to rails and like to integrate the following script "font awesome character" to left side of the words "edit profile" however tried a few ways and its appears below the nav and unable to link. the two pieces to integrate is the link:
<%= link_to "Edit Profile", edit_user_registration_path %>
<i class="fa fa-pencil" aria-hidden="true"></i>
How i integrate the two
Thank you for any support
You can pass a block to a link to add content to the anchor tag
Documentation
<%= link_to(edit_user_registration_path) do %>
<i class="fa fa-pencil" aria-hidden="true"></i>
Edit Profile
<% end %>
My submit button for a comment displays a grey dull button that says "Create Comment". I want to instead display an icon.
I have tried...
<%= f.submit do %>
<i class="fa fa-paper-plane-o" aria-hidden="true"></i>
<% end %>
...with no luck
Do you have your font awesome gem in your gem file and bundled ?
You also need it to be called in your application.css file.
Try this:
<%= f.image_submit_tag(‘<i class="fa fa-paper-plane-o" aria-hidden="true"></i>’).html_safe %>
Reference: image_submit_tag
Try something like this
<%= button_tag(class: "btn btn-default") do %>
<i class="fa fa-paper-plane-o" aria-hidden="true"></i>
<% end %>
Hope this will help you.
I would try something like this:
<%= f.submit '<i class="fa fa-paper-plane-o" aria-hidden="true"></i>'.html_safe %>
I'm using the Kaminari gem for pagination in Rails 4. I want to use the < and > glyphicons (chevron-right and chevron-left) on the side of the pages to go to previous and next page, and can't figure out how to do that. Here's what I have so far:
To make a glyphicon into a link, I can use this:
<%= link_to "some_link" do %>
<i class="glyphicon glyphicon-chevron-right" title="Next Page"></i>
<% end %>
Kaminari also comes with <%= link_to_next_page #pages, 'Next Page' %> but that displays text on the page, not an image
Is there a good way to implement this?
Customize the views/kaminari/_next_page.html.erb in Kaminari
Remove this part of the link_to
raw(t 'views.pagination.next')
and replace with
'<i class="glyphicon glyphicon-chevron-right"></i>'.html_safe
Update
Make sure you have run this so you see the views to modify.
rails generate kaminari:views
For Bootstrap...
rails generate kaminari:views bootstrap
The solution is simple; Using the logic in the explanation Beengie gave, I just needed to include some raw HTML in the link using 'MY_HTML'.html_safe
<%= link_to_next_page #records, '<i class="glyphicon glyphicon-chevron-right"></i>'.html_safe %>
<%= link_to_previous_page #records, '<i class="glyphicon glyphicon-chevron-left"></i>'.html_safe %>
Hello I want to use the icon? or is it the alternative span tag? (No idea what its actually called) Anyways, I want to display a icon in my menu here is my current source code.
<li><i class="material-icons left">person</i><%= link_to signup_path %></li>
This is what I currently get
And here is the html I want it to generate:
<li><i class="material-icons">person/i></li>
Is there anyway to accomplish this in rails?
To create an ERB link in Rails that accomplishes the normal HTML code you provided, do this:
<%= link_to signup_path do %>
<i class="material-icons left">person</i>
<% end %>
This will generate:
<i class="material-icons left">person</i>
Only posting this answer because it is possible to do it this way.. definitely not preferred :)
<%= link_to '<i class="material-icons left">person</i>'.html_safe, signup_path %>
<%= link_to signup_path do %>
<i class="material-icons left"> person </i>
<% end %>
I'm trying to have a Font Awesome icon be hyperlinked with the string of a Rails attribute.
I have tried this,
<%= link_to do %>
<i class="fa fa-link"><% school.website %></i>
<% end %>
this,
<i class="fa fa-link" href="<% school.website %>"></i>
and this:
<i class="fa fa-link" href="<%= school.website %>"></i>
among other variations, and can't seem to get the syntax right.
Would really appreciate some help with the syntax here, can't seem to find a specific answer to how linking with attributes works, only actual static text hrefs.
PS: I'm new to Rails / using Rails 4.2.
Try this:
<%= link_to ('<i class="fa fa-link"></i>').html_safe, desired_path %>
Considering school.website is a URL and you have included icons in CSS, the following will do:
<%= link_to(school.website) do %>
<i class="fa fa-link"></i>
<% end %>
Passing it as a block works too.
<%= link_to school.website do %>
<%= '<i class="fa fa-link"></i>'.html_safe %>
<% end %>
Assuming school.website is a URL that you would like to link to and display the link as well alongside the link icon from font awesome:
<%= link_to("<i class='fa fa-link'></i> #{school.website}".html_safe,school.website) %>
I am going to suggest something a little different.
I am personlly using glyphicons/fa a lot on my website, so I decided to create a little helper in application_helper.rb
application_helper.rb
def fa(glyph, text = nil)
html = "<i class=\"fa fa-#{glyph}\"></i>"
html << " #{text.to_s.html_safe}" if text
html.html_safe
end
And actually the correct syntax to use in views becomes either :
<%= link_to(school.website, class: "xxx") do %>
<%= fa('link') %>
<% end %>
OR (more compact)
<%= link_to(school.website, class: "xxx"){ fa('link') } %>
You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
try this:
<%= link_to(school.website) do %>
<%= fa_icon "fas link" %>
<% end %>