I am running Rails 5 and updated Bootstrap to version 4 in an existing app which uses Devise.
Before updating Bootstrap, the routes were working fine. Now, when the user selects sign-out, they receive the following message:
No route matches [GET] "/users/sign_out"
Here is part of the header code:
<% if current_user %>
<a class=<%= link_to 'Classes', tracks_path %></a>
<a class=<%= link_to 'Edit profile', edit_user_registration_path %></a>
<a class=<%= link_to 'Sign out', destroy_user_session_path, method: :delete %></a>
And Rake Routes shows:
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
Is there a reason that the change to Bootstrap 4 would trigger this error? I have followed all of the instructions on the Bootstrap repo for installation.
The problem is you're rendering your link tags inside the class attribute:
<a class=<%= link_to 'Sign out', destroy_user_session_path, method: :delete %></a>
So that results in malformed output which ignores that you specify method: :delete. This is what you're looking for:
<%= link_to "Sign out", destroy_user_session_path,
method: :delete, class: 'nav-link' %>
Related
I am trying to log out a user from a (test) site in production on heroku.
The problem is heroku transforms this <%= link_to 'Logout', destroy_user_session_path, method: :delete %> in a GET /users/sign_out
I've tried this <%= link_to 'Logout', destroy_user_session_path, method: :delete, :data => { :no_turbolink => true } %> as suggested here Devise destroy_user_session_path does'nt work
I've found some solutions in reply to destroy_user_session_path is triggering GET instead of DELETE in Rails but I don't feel comfortable with the answers as I'd like to avoid a GET.
Logout was ok in development, so I checked on https://devcenter.heroku.com/ and made some modifications, but I am still stuck.
I worked on the asset pipeline and added these gems:
gem 'rails_serve_static_assets'
gem 'rails_stdout_logging'
These gems are probably useful in other cases, but not mine (I also have a problem with links to images that don't persist).
EDIT
Here is my full template
<div class="" style="background-color: #1a252f;">
<ul class="nav justify-content-center">
<% if user_signed_in? %>
<li class="nav-item">
<%= link_to 'Edit account|', edit_user_registration_path %></li>
<li class="nav-item">
<%= link_to 'Logout', destroy_user_session_path, method: :delete, :data => { :no_turbolink => true } %></li>
<% else %>
<li class="nav-item">
<%= link_to 'Login', new_user_session_path %></li>
<% end %>
</ul>
</div>
EDIT 2
I've also tried this in routes.rb:
devise_for :users do
get "/users/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session
end
and I still get a status 404 in the heroku logs.
The solution provided here: destroy_user_session_path is triggering GET instead of DELETE in Rails was the one for me,
i.e. with config.sign_out_via = :get in devise.rb
How can I go about embedding font-awesome icons into my Ruby <%= link_to code?
The below does NOT work, is it possible to accomplish the below some how so that it actually works?
<li><%= link_to "<span class="fa fa-minus-circle fa-1x"></span> Settings</span>", destroy_user_session_path, :method => :delete %></li>
Thanks!
Johnson
have you try this:
<li><%= link_to your_path do %><span class="fa fa-minus-circle fa-1x"></span> Settings <% end %></li>
for instance with font-awesome in some of my codes:
<li><%= link_to edit_contact_path(#contact) do %><i class="fa fa-pencil-square-o"></i> Edit<% end %></li>
<li><%= link_to #contact, method: :delete, data:{confirm: "Delete this contact?"} do %><i class="fa fa-exclamation-triangle"></i> Delete<% end %></li>
Here is the documentation, see the section with link_to ... do .... end
link to documentation
I've always done it including the class in the Ruby code like this,
<li><%= link_to " Sign Up", '#', class: "fa fa-user-plus" %></li>
This includes the icon on the left of the text so you have to include the space preceding "Sign up" in order to get it to look right.
Better option for you is use this gem:
https://github.com/h4b00/awesome_link
After installation you can simply use(for example):
<%= awesome_link('fa-pencil-square-o', root_path, method: :update) %>
I have this link
<li><a href="<%= destroy_user_session_path(:method => :delete) %>"><button
class="button icon-left ion-ios7-compose">Log out</button></a></li>
But it is not working. How do I fix the :method => :delete so that it works in the link?
I am getting this error:
No route matches [GET] "/users/sign_out"
Also, I am using devise for users.
use the link_to helper (also check out your html, a button isn't usually found inside a link).
<li><%= link_to 'Log out', destroy_user_session_path, method: :delete %></li>
You have to write it like this
<li><%= link_to "Log Out", destroy_user_session_path, :class => "button icon-left ion-ios7-compose", :method => :delete %></li>
I'm using devise for user authentication. In my views I've set:
<% if user_signed_in? %>
<li><%= link_to "Log Out", destroy_user_session_path %></li>
<% else %>
<li><%= link_to "Sign In", new_user_session_path %></li>
<% end %>
However when I click Log_Out I'm getting an error:
No route matches [GET] "/users/sign_out"
However when I check my rake routes I'm getting:
devise/sessions#destroy destroy_user_session DELETE /users/sign_out(.:format)
What apneadiving said.
<%= link_to "Log Out", destroy_user_session_path, method: :delete %>
Default sign out is use "delete" method. Your route also said the method is “DELETE"
If you want use "get" method
Modify devise.rb to
config.sign_out_via = :get
Baloo is right, make sure to use the :delete method. You can see this clearly if you invoke
rake routes
You'll see the path as well as the method.
I've searched for an answer to this and nothing has helped.
I have the following in my view:
<div id="user_nav">
<% if user_signed_in? %>
Logged in as <strong><%= current_user.first_name + " " +current_user.last_name%></strong>.
<%= link_to 'Edit profile', edit_user_registration_path %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to "Sign up", new_user_registration_path %> |
<%= link_to "Login", new_user_session_path %>
<% end %>
Which is straight from the railscast on devise. Suddenly the paths are not working anymore. (sign up or sign in) for example when I click login i get the error
No route matches {:controller=>"devise/home", :action=>"students"}
Ive tried using <%= link_to "Login", :controller => '/devise/sessions', :action => 'new' %> jsut for kicks and it returns the same error.
Yes I have devise_for :users in my route file.
rake routes return all the right routes including
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
Any help would be awesome! I'm stumped!
Looking at my stack trace, something (a link) in my layout was throwing it off. I created a custom layout for devise and everything works fine now.