How to assign a link to omniauth facebook button - css

This is the code I have:
<div class="col-md-6 col-sm-6 col-xs-6">
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in", omniauth_authorize_path(resource_name, provider) %>
<% end -%>
<% end -%>
</div>
From the code above how can I change link_to "Sign in" with:
<button class="btn btn-facebook btn btn-lg btn-block"><i class="fa fa-facebook fa-2x"></i> | Connect with <br> Facebook</button>
So instead of "sign in" simple button, I will show my custom made Facebook button.

Answer: this is how i solved it
<div class="col-md-6 col-sm-6 col-xs-6">
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to omniauth_authorize_path(resource_name, provider), class: 'btn btn-facebook btn btn-lg btn-block' do %>
<i class="fa fa-facebook fa-2x"></i>
|Connect with <br> Facebook
<% end %>
<% end -%>
<% end -%>
</div>
and it looks like this
when someone clicks on that,it gets redirected to the required path,which is omniauth_authorize_path(resource_name, provider)
for those who need the css code for this button here it is
.btn-facebook.btn.btn-lg.btn-block {
color: white;
background-color: DodgerBlue;
font-size: 1em;
&:hover {
color: white;
background-color: RoyalBlue;
}
}
I would appreciate if someone,would tell me how to make the "f" icon,to be in the center of the button.
Thank you

What I did:
<%= link_to raw('<span class="fa fa-facebook"></span> Ingresa con Facebook'), user_omniauth_authorize_path(:facebook), :class => 'btn btn-block btn-social btn-facebook form-control' %>
Im using the bootstrap-social gem and the font-awesome gem to style it exactly like facebook looks :P
https://github.com/gavinkflam/bootstrap-social-rails

Related

Image grid as button in bootstrap

I have 4 images with different sizes. I want to create a grid of 2x2 with each block is equal to each other and it is a clickable image (work as a button). How can I do this in CSS/Bootstrap?
This is what I have tried (in Rails):
<div class="row row-cols-2 main-wrapper px-4">
<%= link_to students_path, class:"nav-link col btn btn-light center-div" do %>
<%= image_tag "/assets/bg/cs-ds-bg.jpeg" %>
<p class="h2">Student stories & Research</p>
<% end %>
<%= link_to faculties_path, class:"nav-link col btn btn-light center-div" do %>
<%= image_tag "/assets/bg/cs-bg.jpeg" %>
<p class="h2">Faculty & Staff</p>
<% end %>
<%= link_to courses_path, class:"nav-link col btn btn-light center-div" do %>
<p class="h2">Courses</p>
<% end %>
<%= link_to requirements_path, class: "nav-link col btn btn-light center-div" do %>
<p class="h2">Computer Science & Data Science <br>
Major & Minor Requirements</p>
<% end %>
</div>
CSS:
.main-wrapper {
height: 80vh;
}
.center-div {
display: flex;
align-items: center;
justify-content: center;
border: 0.5px solid #000000;
}
This is the image of what it looks right now
Thank you!

Bootstrap icon misalignment [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Closed 3 years ago.
I am trying to align my words with icon. I tried the methods from this site: Vertical alignment of text and icon in button
current state
My code:
<div class = "row">
<div class = "col-md-8">
<h3><%= link_to item.title, item , id: "font-colour" %></h3>
<p><%= if item.description.length > 70
item.description[0..70].gsub(/\s\w+\s*$/, '...')
else
item.description
end
%></p>
</div>
<%= link_to complete_item_path(item), id: "font-colour", method: :patch do %>
<i class="fa fa-square-o fa-2x align-center"></i>
<% end %>
<div class = "col-md-1">
<%= link_to item_path(item), id: "font-colour", method: :delete do %>
<i class="fa fa-trash fa-2x align-center"></i>
<%end%>
</div>
</div>
Adding display: flex;align-items: center; to row could be helpful:
<div class = "row" style="display: flex;align-items: center;">
<div class = "col-md-8">
<h3><%= link_to item.title, item , id: "font-colour" %></h3>
<p><%= if item.description.length > 70
item.description[0..70].gsub(/\s\w+\s*$/, '...')
else
item.description
end
%></p>
</div>
<%= link_to complete_item_path(item), id: "font-colour", method: :patch do %>
<i class="fa fa-square-o fa-2x align-center"></i>
<% end %>
<div class = "col-md-1">
<%= link_to item_path(item), id: "font-colour", method: :delete do %>
<i class="fa fa-trash fa-2x align-center"></i>
<%end%>
</div>
</div>

Remove Button Styling From f.submit in Rails Form

I have a simple form that simply sets the #active attribute to true/false. Within the form there is only one single hidden_field. Here is how I currently have the submit button for the form looking when the #active status is true.
When clicked, the form will submit and change the #active attribute to false. When redisplayed it will look like this:
.
Basically the form functions as a toggle switch that behind the scenes submits a form which toggles an attribute to true/false.
It works wonderfully. However, I do not want any of the default button styling. I don't want that gray box or the border. Instead: I only want to show that font-awesome glyphicon for the button, and that is it.
Here is the code I currently have which displays the glyphicon with the gray button css:
<td>
<%= form_for blog do |f| %>
<% if blog.active %>
<%= f.hidden_field :active, value: false %>
<% else %>
<%= f.hidden_field :active, value: true %>
<% end %>
<% if blog.active? %>
<%= f.button do %>
<i class="fa fa-toggle-on fa-2x text-success" aria-hidden="true"></i>
<% end %>
<% else %>
<%= f.button do %>
<i class="fa fa-toggle-off fa-2x text-danger" aria-hidden="true"></i>
<% end %>
<% end %>
<% end %>
</td>
Question: How can I take the button styling off of the f.submit button and only have the glyphicon to represent the submit button?
Would love to hear if there is a better solution. Basically all I did was added a new css class which sets the background property to none and the border property to none.
<% if blog.active? %>
<%= f.button, class: 'remove-submit-btn-style' do %>
<i class="fa fa-toggle-on fa-2x text-success" aria-hidden="true"></i>
<% end %>
<% else %>
<%= f.button, class: 'remove-submit-btn-style' do %>
<i class="fa fa-toggle-off fa-2x text-danger" aria-hidden="true"></i>
<% end %>
<% end %>
And then in app/assets/stylesheets/application.scss
.remove-submit-btn-style {
background: none;
border: none;
}

Change the size of a bootstrap button in a div

I am using bootstrap buttons in my code. I would like to change certain buttons in a particular div however. The should be smaller
<div class="well">
<div class="bookmark">
<% #bookmarks.each do |bookmark| %>
<p>
<%= link_to bookmark.url %>
#these should be smaller
<%= link_to "Edit bookmark", edit_topic_bookmark_path(#topic, bookmark), class: "btn btn-danger" %>
<%= link_to "Destroy bookmark", [#topic, bookmark], method: :delete, class: "btn btn-danger" %>
</p>
<%= render partial: 'favorites/favorite', locals: { favorite: #favorite, bookmark: #bookmark } %>
<% end %>
</div>
<%= link_to "New bookmark", new_topic_bookmark_path(#topic), class: 'btn btn-default' %>
</div>
I was trying do this adding this to my application.css.scss file
.bookmarks btn {
size: 2px;
}
But this does not seem to work. Any suggestions?
try this:
<p>
<%= link_to bookmark.url %>
#these should be smaller
<%= link_to "Edit bookmark", edit_topic_bookmark_path(#topic, bookmark), class: "btn btn-danger btn-sm" %>
<%= link_to "Destroy bookmark", [#topic, bookmark], method: :delete, class: "btn btn-danger btn-sm" %>
</p>
You could these classes for sizing buttons:
btn-lg
btn-sm
btn-xs
bootstrap documentation
Did you try the bootstrap button size classes?
You custom css for the button could be something like.
.custom-button {
font-size:0.8em;
padding:5px;
}
Where you lower the padding and font size to reduce the size.
I think the quick way is make it important
.bookmarks btn {
size: 2px!important;
}

How can I make the twitter-like hover 'Follow' button with bootstrap?

Now I have the button with which, I can follow user, or un-follow.
Now when the target user is already followed. it's shown just like this.
Then the target user is not followed, it's shown just like this.
I'd like it to be shown 'following' when the target user is already followed.
Then when I bring mouse cursor over the button, the display should be changed to 'Un-Follow'.
How can I do that with bootstrap?
view
<% if user_signed_in? %>
<% unless user == current_user %>
<% if current_user.following?(user) %>
<%= link_to(unfollow_user_path(user), :remote => true, :class => 'btn') do %>
<i class="icon-remove"></i>
Un-Follow
<% end %>
<% else %>
<%= link_to(follow_user_path(user) ,:remote => true, :class => 'btn btn-primary') do %>
<i class="icon-ok icon-white"></i>
Follow
<%end%>
<% end %>
<% end %>
<% else %>
<%= link_to(new_user_session_path , :class => 'btn btn-primary') do %>
<i class="icon-ok icon-white"></i>
Follow
<%end%>
<% end %>
HTML
<a href="/user/1/follow" class="btn btn-primary" data-remote="true">
<i class="icon-ok icon-white"></i>
Follow
</a>
<a href="/user/1/unfollow" class="btn btn-primary" data-remote="true">
<i class="icon-remove icon-white"></i>
Un-Follow
</a>
UPDATE:
<a href="/user/1/unfollow" class="btn" data-remote="true" onhover="someFunction()">
<i id="Following" class="icon-remove"></i>
Following
</a>
Using the onHover event You can use jQuery to change the "class" attribute of the button you want to change the text too.
i.e.
<a href="/user/1/follow" onHover="someFunction();" class="btn btn-primary" data-remote="true">
<i id="Following" class="icon-ok icon-white"></i>
Following
</a>
someFunction() {
$('i#Following').attr("class", "icon-ok icon-white").innerText("Unfollow");
}
you get the picture hopefully.
Edit:
This is the full code that should fire the code in someFunction on mouse over.
<html>
<head>
<script type="text/javascript">
function someFunction()
{
alert("Hello");
}
</script>
</head>
<body>
<a href="/user/1/unfollow" class="btn" data-remote="true" onmouseover="someFunction();return true;" >
<i id="Following" class="icon-remove"></i>
Following
</a>
</body>
</html>

Resources