No route matches [GET] " / użytkownicy / Wyloguj się"

Oto mój rzeczywisty błąd: No route matches [GET] "/members/sign_out" Ponieważ większość ludzi będzie używać "użytkownicy" pomyślałem, że byłoby bardziej pomocne, aby mieć to w tytule. W każdym razie nie mogę się wylogować. Mogę z powodzeniem edytować mój profil użytkownika.

Używam devise 1.4.2 i Rails 3.1.0.rc4. Wygenerowałem również dwa oddzielne modele devise - jeden o nazwie "członkowie", a drugi o nazwie"administratorzy". Udało mi się zarejestrować i zalogować do obu (jednocześnie), ręcznie przechodząc do właściwej ścieżki URL (np. localhost: 3000 / admins/sign_in/). Utworzyłem kilka linków w mojej aplikacji.html.plik układu haml wykonując ten RailsCast na Devise. Zdaję sobie sprawę, że dotyczy tylko linków signin/signout dla " członków."

Po kliknięciu na link logowania otrzymuję powyższy błąd. Dzieje się tak, jeśli ręcznie przejdę do adresu URL logowania (np. localhost:3000/admins/sign_out/).

Czy ktoś może mi powiedzieć, dlaczego to się dzieje? Poniżej znajdują się różne powiązane pliki. I oczywiście jestem nowicjusz...

Wyjście trasy Rake:

    j(film_repo)$ rake routes
        new_member_session GET    /members/sign_in(.:format)       {:action=>"new", :controller=>"devise/sessions"}
            member_session POST   /members/sign_in(.:format)       {:action=>"create", :controller=>"devise/sessions"}
    destroy_member_session DELETE /members/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}
           member_password POST   /members/password(.:format)      {:action=>"create", :controller=>"devise/passwords"}
       new_member_password GET    /members/password/new(.:format)  {:action=>"new", :controller=>"devise/passwords"}
      edit_member_password GET    /members/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
                           PUT    /members/password(.:format)      {:action=>"update", :controller=>"devise/passwords"}
cancel_member_registration GET    /members/cancel(.:format)        {:action=>"cancel", :controller=>"devise/registrations"}
       member_registration POST   /members(.:format)               {:action=>"create", :controller=>"devise/registrations"}
   new_member_registration GET    /members/sign_up(.:format)       {:action=>"new", :controller=>"devise/registrations"}
  edit_member_registration GET    /members/edit(.:format)          {:action=>"edit", :controller=>"devise/registrations"}
                           PUT    /members(.:format)               {:action=>"update", :controller=>"devise/registrations"}
                           DELETE /members(.:format)               {:action=>"destroy", :controller=>"devise/registrations"}
         new_admin_session GET    /admins/sign_in(.:format)        {:action=>"new", :controller=>"devise/sessions"}
             admin_session POST   /admins/sign_in(.:format)        {:action=>"create", :controller=>"devise/sessions"}
     destroy_admin_session DELETE /admins/sign_out(.:format)       {:action=>"destroy", :controller=>"devise/sessions"}
            admin_password POST   /admins/password(.:format)       {:action=>"create", :controller=>"devise/passwords"}
        new_admin_password GET    /admins/password/new(.:format)   {:action=>"new", :controller=>"devise/passwords"}
       edit_admin_password GET    /admins/password/edit(.:format)  {:action=>"edit", :controller=>"devise/passwords"}
                           PUT    /admins/password(.:format)       {:action=>"update", :controller=>"devise/passwords"}
 cancel_admin_registration GET    /admins/cancel(.:format)         {:action=>"cancel", :controller=>"devise/registrations"}
        admin_registration POST   /admins(.:format)                {:action=>"create", :controller=>"devise/registrations"}
    new_admin_registration GET    /admins/sign_up(.:format)        {:action=>"new", :controller=>"devise/registrations"}
   edit_admin_registration GET    /admins/edit(.:format)           {:action=>"edit", :controller=>"devise/registrations"}
                           PUT    /admins(.:format)                {:action=>"update", :controller=>"devise/registrations"}
                           DELETE /admins(.:format)                {:action=>"destroy", :controller=>"devise/registrations"}
                     films GET    /films(.:format)                 {:action=>"index", :controller=>"films"}
                           POST   /films(.:format)                 {:action=>"create", :controller=>"films"}
                  new_film GET    /films/new(.:format)             {:action=>"new", :controller=>"films"}
                 edit_film GET    /films/:id/edit(.:format)        {:action=>"edit", :controller=>"films"}
                      film GET    /films/:id(.:format)             {:action=>"show", :controller=>"films"}
                           PUT    /films/:id(.:format)             {:action=>"update", :controller=>"films"}
                           DELETE /films/:id(.:format)             {:action=>"destroy", :controller=>"films"}
                      root        /                                {:controller=>"films", :action=>"index"}

Trasy.rb

FilmRepo::Application.routes.draw do
  devise_for :members

  devise_for :admins

  resources :films

  root :to => 'films#index'
end

Admin.rb (model)

class Admin < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

Member.rb (model)

class Member < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

Zastosowanie.html.haml

!!!
%html
    %head
        %title Film Repo
        = stylesheet_link_tag 'compiled/screen.css', :media => 'screen, projection'
        = stylesheet_link_tag 'compiled/print.css', :media => 'print'
        /[if lt IE 8]
            = stylesheet_link_tag 'compiled/ie.css', :media => 'screen, projection'
            = csrf_meta_tag
    %body.bp
        #container
            #user_nav
                - if member_signed_in?
                    Signed in as #{current_member.email}. Not you?
                    \#{link_to "Sign out", destroy_member_session_path}
                - else
                    = link_to "Sign up", new_member_registration_path
                    or #{link_to "sign in", new_member_session_path}
                - flash.each do |name, msg|
                    = content_tag :div, msg, :id => "flash_#{name}"
            = yield
Author: Joe, 0000-00-00

19 answers

Miałem podobny problem, ale dodanie :method=>: delete nie zadziałało. Udało mi się dodać nową trasę dla żądania get, komentując devise_for: users i dodając

devise_for :users do
  get '/users/sign_out' => 'devise/sessions#destroy'
end
 43
Author: cramhead,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-11 14:01:32

Możesz zakończyć sesję poprzez get, zmieniając konfigurację devise w initializers.

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :get

Po prostu otwórz link, a Twoja sesja zostanie usunięta.

 41
Author: itkevin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-11 19:00:04

Chociaż nie znam przyczyny, powodem, dla którego otrzymujesz tę wiadomość jest to, że w Twoich trasach masz

destroy_member_session DELETE /members/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}

Co oznacza, że trasa jest dostępna tylko z metodą DELETE w przeciwieństwie do GET. Jest to trochę dziwne, ponieważ w docs for devise jest napisane, że powinien utworzyć go jako GET route (https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L30)

Z nim jako trasą DELETE, powinieneś być w stanie wylogować się za pomocą

link_to :logout, destroy_member_session_path, :method => :delete 
 20
Author: Olives,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-07-04 17:14:11

Miałem podobny problem. Mój kod widoku był taki:

  <%= link_to " exit", destroy_user_session_path, method: :delete %>

Po dodaniu następującej zmiany do tras.RB zadziałało,

devise_for :users

devise_scope :user do  
   get '/users/sign_out' => 'devise/sessions#destroy'     
end
 16
Author: Reza,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-07 07:56:31

I just needed to add the

//= require jquery
//= require jquery_ujs

Do mojego application.js

 16
Author: Victor Martins,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-06 02:12:29

Nadal możemy użyć :method => :delete w moim kodzie, tak jak

 = link_to "Sign out", destroy_user_session_path,:method => :delete

Powodem, dla którego myślę, że nie możemy załadować javascript, który zawiera jquery, upewnij się

= javascript_include_tag "application" (haml- you can use html too)

Aby dołączyć jquery-ui i jQuery-ujs. Więc jeśli nadal jest błąd, proponuję zmienić rails gem w GEMFILE na wersję 3.2.6 i wywołać bundle update, aby zaktualizować gems. Dla mnie działa!

 6
Author: duykhoa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-11 18:16:10
= link_to "Sign out", destroy_user_session_path,:method => :delete

Will NOT work instead this,

= link_to "Sign out", destroy_user_session_path,:method => 'delete'

Należy wykonać trik lub gorzej dodać require jquery_ujs w aplikacji .js

 5
Author: Nikhil Nanjappa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-01 10:36:32

W devise.RB, change

 config.sign_out_via = :delete

Do

config.sign_out_via = :get
To mi pomogło. Oszalałem z tym, bo domyślnym jest delete i nie rozumiem dlaczego.

To działa, ale nie jestem pewien, czy wpływa na inne elementy w aplikacji.

 5
Author: loloso,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-12 09:54:52

Używając Rails4, musiałem użyć następującej metody:

<%= link_to "Logout", destroy_admin_session_path, method: :delete %>

Podkreślenie, gdzie są dwukropki na method :and: delete

 4
Author: Sam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-25 12:18:54

Może to komuś pomoże. Uaktualniony z Rails 3.0 do 3.1 i znalazł ten problem. To mi to naprawiło:

Trasy.rb:
devise_for: użytkownicy

Devise.rb:
config.sign_out_via =: delete

Zastosowanie.html.erb:

<%= javascript_include_tag "application" %>     

* not: defaults

_login_items.html.erb:

<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>

App / assets/javascripts / application.js

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

I miałem w javascript / jquery.js, jquery_ujs.js od wersji 3.0 to usunąłem.

 3
Author: Katya B,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-13 23:19:37

Możesz usunąć zasoby / javascripts/ *

Uruchom rails generate jquery:install --ui spowoduje to wygenerowanie wszystkich skryptów javascripts, jak pokazano poniżej

xxxx@xxxxx:~/Projects/Rails_apps/rtest$ rails generate jquery:install --ui
      remove  public/javascripts/prototype.js
      remove  public/javascripts/effects.js
      remove  public/javascripts/dragdrop.js
      remove  public/javascripts/controls.js
     copying  jQuery (1.7.1)
      create  public/javascripts/jquery.js
      create  public/javascripts/jquery.min.js
     copying  jQuery UI (1.8.16)
      create  public/javascripts/jquery-ui.js
      create  public/javascripts/jquery-ui.min.js
     copying  jQuery UJS adapter (822920)
      remove  public/javascripts/rails.js
      create  public/javascripts/jquery_ujs.js

Przejdź do układu np. aplikacji.html.erb I edit <%= javascript_include_tag :all %>

To mi pomogło:)

 3
Author: Bernard Banta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-29 17:13:33

FWIW też napotkałem ten problem. Przyjrzałem się wszystkim sugerowanym odpowiedziom, jednak jedynym, który zadziałał, było sfotografowanie otwartych tras.rb i skomentuj następujący wiersz:

devise_for :users

Poniżej, dodaj następujący wiersz:

devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
 2
Author: Jason,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-13 00:44:18

Problem zaczyna się od rails 3.1 w assets/javascript/. Po prostu poszukaj application.js, a jeśli plik nie istnieje, utwórz plik o tej nazwie. Nie wiem dlaczego mój plik znika lub nigdy nie został stworzony na rails new app... ten plik jest instancją jquery.

 2
Author: rome3ro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-10 23:53:29

@creamhost powiedz,

devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end

Ale nie jest to dla mnie poprawne rozwiązanie (Rails4). Rozwiązałem nasz problem(odpowiedź @ oliwki),

link_to :logout, destroy_member_session_path, method: :delete
 2
Author: seyyah,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-01 01:39:19

Po prostu użyj poniższego linku Wyloguj się:

<%= link_to "Sign out", destroy_user_session_path, method: :delete %>
 1
Author: phildub,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-10-19 00:06:26
//= require jquery_ujs
Brakuje ci tej linii w Twoich aktywach. Nie ma potrzeby otrzymywania /users/signout prośby. Umieść tę linię w pliku JavaScript na górze strony.
 1
Author: Idrees Ibrahim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-02 12:24:33

Miałem ten sam problem i pamiętałem, że zaczęło się to dopiero po tym, jak zdecydowałem się "wyczyścić" moje pliki Javascript. Więc uruchomiłem rails generate jquery:install --ui ponownie i to rozwiązało to za mnie. (Możesz zignorować część --ui, jeśli nie potrzebujesz jQuery UI, jak sądzę.)

 0
Author: octimizer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-07-19 20:02:36

Otrzymywałem ten sam błąd, który miał OP dla / users / sign_out, ponieważ otrzymywałem go zamiast usuwać (ja też jestem 1st year dev). Po sprawdzeniu github za pomocą tej odpowiedzi, przesłałem pull request, aby go poprawić!

Https://github.com/plataformatec/devise/pull/2040

Go S. O. !!!

 0
Author: RudyOnRails,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-08-23 16:40:27

Dzieje się to tylko w systemie windows.. Dodaj następującą rzecz do swojej aplikacji.html.plik erb.

Devise_for: users

Devise_scope: user do
get '/ users / sign_out ' = > 'devise/sessions#destroy'
end

 -2
Author: Kartikey Garg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-05 21:43:56