Bootstrap Sass broke devise - ruby-on-rails

Hi I hope someone can help. I i'm building a news application on rails. I installed devise and act-as-votable for posts. I then installed bootstrap-sass (twbs/bootstrap-sass) and devise wont render to the screen.
<% if user_signed_in? %>
<div class="index_log">
Hey, your logged in as <strong><%= current_user.email %></strong>.
<% if user_signed_in? %>
<%= button_to "Log Out", destroy_user_session_path, method: :delete, class: 'btn btn-default navbar-btn' %>
<% else %>
<%= link_to "Log In", new_user_session_path, class: 'btn btn-default navbar-btn', method: :get %>
<% end %>
When I go go to the login page, enter my username and password, nothing happens.
Or else I create a new user, again nothing happens.
Any Ideas - I would add code below but I'm not sure what to add.

Looks like you have an extra if user_signed_in? tag
Hey, your logged in as <strong><%= current_user.email %></strong>.
<% if user_signed_in? %>
and that is messing up your <% else %> (which now matches the extra if and is now nested within the first if user_signed_in? and will never be rendered.
Also, unrelated, but it should be "...you're logged in as..." and the div class="index_log" isn't closed

Related

Chaning image-button to text-button using Devise login

I have it currently so someone can click on the login button and when somebody signs in it changes that to logout. How would I be able to make it so it sets the button as the user's avatar that they have uploaded (or default one) when they login and then when they logout it changes back to "sign in"?
<div class="dropdown">
<button class="button-login">
<% if user_signed_in? %>
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to "Login", new_user_session_path %>
<% end %>
</button>
<div class="dropdown-content">
<p>
<% if user_signed_in? %>
<%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %>
<% else %>
<%= link_to "Sign up", new_user_registration_path %>
<% end %>
</div>
I believe you can do this by using a block:
<%= link_to destroy_user_session_path, method: :delete do %>
<%= image_tag("avatar.jpg", :alt => "user avatar image") %>
<% end %>

Extra blank <a></a> showing up

When I go to my menu to sign in it works perfectly fine and there is nothing extra but when I am signed in there is an extra blank at the top. How can I fix this?
Server Side html.erb
<div id="myDropdown" class="dropdown-content">
<% if user_signed_in? %>
<a><%= link_to('My Account', edit_user_registration_path) %>
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
<% else %>
<%= link_to('Log in', new_user_session_path) %>
<%= link_to('Sign up', new_user_registration_path) %></a>
<% end %>
</div>
Client Side Html (Logged In)
<a></a>
My Account
<a rel="nofollow" data-method="delete" href="/users/sign_out">Sign out</a>
What it looks like
I think you don't have to write explicit tag
<%= link_to "Home", root_path %>
# => Home
So
<%= link_to('My Account', edit_user_registration_path %>
# => My Account
To remove the extra href tag one, just remove the tag and its closing from your code. and it will render the view correctly.
More Information about link_to helper method

How can I get the 'Sign Up' link in the header to disappear after the user logs in

enter image description here
I am developing my first RAILS application whilst using the Devise GEM for authentication.
I would like users who have Signed Up already and are subsequently Signed In to my application (to have the "Signed Up' link in the header not be made available to them).
Can someone kindly guide me as to how I can modify my attached syntax to provide this.
Thank you in advance of your help.
enter image description here
Using the Devise gem for user authentication, you can verify if a user is signed in using the user_signed_in? helper method:
<% if user_signed_in? %>
<%= button_to "SIGN OUT", destroy_user_session_path, :method => :delete %>
<% else %>
<%= button_to "SIGN IN", new_user_session_path, :method => "get" %>
<%end %>
Here you are checking if the user_signed_in? return true and if so, you will show the sign out path to destroy a user's session.
From the link you provided (http://i.stack.imgur.com/ZZU3P.png) your problem is that you did not wrap the <%= link_to "signup", new_user_session_path %> into the conditional statement.
So to solve your problem you should do this:
<% if user_signed_in? %>
<%= link_to "logout", destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to "signup", new_user_registration_path %>
<%= link_to "signin", new_user_session_path %>
<%end%>

Authorization set up for Rails app with VK

I have application which works on Rails. I am using devise and omniauth-vkontakte.
My app can authorize user with vk.com but after user has passed authorization my navigation menu disappears.
Navigation menu code is in views/layouts/application.html.erb:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="authentication">
<% if user_signed_in? %>
<span>Hello, <%= current_user.email %></span>
<%= button_to 'Exit', destroy_user_session_path, {:method => :delete} %>
<% else %>
<%= button_to 'sign up', new_user_registration_path,
{class: 'btn btn-default navbar-btn btn-info', id: 'sign-up-link', :method => :get} %>
<%= button_to 'sign in', new_user_session_path, {class: 'btn btn-default navbar-btn btn-info', id: 'sign-in-btn'} %>
<% end %>
</div>
</div>
</nav>
And I have one more trouble. How can I do that when user has passed authorization via vkontakte there will be a exit button that redirects to the main page?
Now it works like this: user passes auth with vkontankte and I have this message:
Users::OmniauthCallbacks#vkontakte
Find me in app/views/users/omniauth_callbacks/vkontakte.html.haml
Code in app/views/users/omniauth_callbacks/vkontakte.haml.html:
%h1 Users::OmniauthCallbacks#vkontakte
%p Find me in app/views/users/omniauth_callbacks/vkontakte.html.haml
Code in app/controllers/users/omniauth_callbacks_controller.rb:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def vkontakte
end
end
After authorization it redirects you to def vkontakte end method and you see it view.
So you can add some modification to this controller, something like redirect_to root_path. I don't now how you build your system but here example how you could implement it: link (on Russian, but you can look at code)

user_signed_in? is always true

I have no user in my db
I have a rails3 application with devise. No change from default installation, but I have this strange problem:
<h1>Home</h1>
<% if (user_signed_in?) %>
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>.
<% end %>
Is always true. Also with no user and with no logged user. What could it be ????
Use current_user instead
<h1>Home</h1>
<% if current_user %>
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>.
<% end %>

Resources