How to add glyphicon to link_to - ruby-on-rails

I am trying to replace the word "like" with a heart icon.
Basically, I am trying to add <i class="glyphicon glyphicon-heart"></i> to the following:
<%= link_to 'Like', like_post_path(post), method: :post %>

Try something like
<%= link_to like_post_path(post), method: :post do %>
<i class="glyphicon glyphicon-heart"></i>
<% end %>

This is for you
<%= link_to '<i class="glyphicon glyphicon-heart"></i> Like'.html_safe, like_post_path(post), method: :post %>

Related

NoMethodError: undefined method `stringify_keys' for "/auctions/2/comments/9":String Rails [duplicate]

I have this edit button:
<%= link_to edit_income_path(trans), class: "btn btn-default" do %>
<i class="glyphicon glyphicon-pencil"></i>
<% end %>
And I want a delete button to look the same with this icon: glyphicon glyphicon-trash, but I can't find the right syntax to make it work and look the same. My delete button now:
<%= button_to "delete", trans, :method=> :delete, :remote=> true %>
Is this what you are looking for??
<%= button_to trans, method: :delete, remote: true, class: "btn btn-default" do %>
<span class="glyphicon glyphicon-trash"></span>
<% end %>
try this...for example with link_to
<%= link_to (‘<i class=“fa fa-thumbs-up fa-lg”> </i>’).html_safe, vote_path(#image), :method=> :delete, :remote=> true%>

RAILS 4: problems with 'delete' button

I have a nested resource, comments like so....
resources :microposts do
member do
get :upvote, :undo_upvote
end
member do
get :follow, :unfollow
end
resources :responses do
member do
get :upvote, :undo_upvote
end
resources :comments
end
end
I have a delete button on the comments index page....
<div class = "Comment" id="comment-<%= comment.id %>">
<%= link_to comment_avatar_for(comment.user), comment.user %>
<span class="Commentator">
<%= comment.user.full_name %>
</span>
<span class="content">
<%= comment.body %>
</span>
<span class="timestamp">
Posted <%= time_ago_in_words(comment.created_at) %> ago.
</span>
<span class="timestamp">
<% if current_user?(comment.user) %>
<%= link_to "delete", comment, method: :delete, data: { confirm: "You sure?" }, :class => "btn btn-default btn-xs delete" %>
<% end %>
</span>
</div>
And I am getting this error when I load the page
undefined method `comment_path' for #<# <Class:0x007f8936876e70>:0x007f8931857020>
I am uncertain why this isn't working - after all I have the correct instance of 'comment'. If someone could just point me in the right direction I would be grateful.
Rails makes assumptions.
Because you have an instance of Comment it assumes you're going to be using comment_path, but you don't have that as per your routes so you need to set the correct path:
<%= link_to "delete", micropost_response_comment_path(#micropost, #response, comment), method: :delete, data: { confirm: "You sure?" }, :class => "btn btn-default btn-xs delete" %>
I might have the path wrong, but hopefully you get the idea.

No route matches [GET] "/links/www.twitter.com.au"

Hello building a reddit clone.
When i click on this link found here http://postimg.org/delete/saq41zozs/ it should go another website. In this case it's www.twitter.com.au
Error found here http://postimg.org/delete/uhlsxso1e/
Im guessing because i don't have a twitter.com route. I don't know how to set it up so it routes to twitter.com
Here's my routes.rb.
Rails.application.routes.draw do
resources :comments
devise_for :users
resources :links do
member do
put "like", to: "links#upvote"
put "dislike", to: "links#downvote"
end
resources :comments
end
root "links#index"
Here is my show.html.erb
<div class="page-header">
<h1><%= #link.title %><br> <small>Submitted by <%= #link.user.name %></small></h1>
</div>
<div class="btn-group">
<%= link_to 'Visit URL', #link.url, class: "btn btn-primary" %>
</div>
<div class="btn-group pull-right">
<%= link_to like_link_path(#link), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-up"></span>
Upvote
<%= #link.get_upvotes.size %>
<% end %>
<%= link_to dislike_link_path(#link), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-down">
Downvote
<%= #link.get_downvotes.size %>
<% end %>
</div>
<% if #link.user == current_user -%>
<div class="btn-group">
<%= link_to 'Edit', edit_link_path(#link), class: "btn btn-default" %>
<%= link_to 'Destroy', #link, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-default" %>
</div>
<% end %>
<h3 class="comments_title">
<%= #link.comments.count %> Comments
</h3>
<div id="comments">
<%= render :partial => #link.comments %>
</div>
<%= simple_form_for [#link, Comment.new] do |f| %>
<div class="field">
<%= f.text_area :body, class: "form-control" %>
</div>
<br>
<%= f.submit "Add Comment", class: "btn btn-primary" %>
<% end %>
As you are linking to an external site, as opposed to a relative url, you need to prepend your link with 'http'. Just change the link in question to:
<div class="page-header">
<h1><%= link_to #link.title, "http://#{#link.url}" %><br> <small>Submitted by <%= #link.user.name %></small></h1>
</div>

How to add a method to link_to do ViewHelper in Rails

Thats the original Devise logout link which works:
link_to("Logout", destroy_user_session_path, :method => :delete)
Because of the and the I had to switch to this kind of link. The problem now is the link try to find the user sign_out
Tried:
<%= link_to (destroy_user_session_path, :method => :delete) do %>
<i class="icon-off"></i> Logout</span>
<% end %>
and
<%= link_to (destroy_user_session_path, method => :delete) do %>
<i class="icon-off"></i> Logout</span>
<% end %>
and
<%= link_to (destroy_user_session_path, :method = 'delete') do %>
<i class="icon-off"></i> Logout</span>
<% end %>
Any ideas or suggestions?
I would do,
<span>
<i class="icon-off">
</i>
<%= link_to("Logout",destroy_user_session_path, :method => :delete)%>
</span>

How do I generate a <button> tag with an <i> inside?

I want to produce this HTML:
<a class="action-btn btn-delete" href="/product/9">
<i class="icon-trash icon-white"></i>
</a>
But I read that I need to use the button_to helper method, rather than link_to.
So I tried this:
<%= button_to product, method: :delete, class: "action-btn btn-delete" do %>
<i class="icon-edit icon-white"></i>
<% end %>
But that doesn't work.
Thoughts?
I think you can use the link_to:
<%= link_to product, :method => "DELETE", :class => "action-btn btn-delete" do %>
<i class="icon-edit icon-white"></i>
<% end %>
I don't see how you can't use [link_to][1]
<%= link_to product, class: "action-btn btn-delete" do %>
<i class="icon-edit icon-white"></i>
<% end %>
Try, it may work,
<%= link_to product, method: :delete, class: "action-btn btn-delete" do %>
<i class="icon-edit icon-white"></i> Delete
<% end %>

Resources