使用 Spree 登录 link 时遇到问题

having problems with the login link using Spree

所以我尝试按照 http://guides.spreecommerce.org/developer/authentication.html However I haven't been able to get the link on my app.

中的文档在我的 Spree Rails 应用程序上添加登录名 link

我根据文档创建了 app/overrides/auth_login_bar.rb 文件,并在文件中添加了以下代码。

Deface::Override.new(:virtual_path => "spree/shared/_nav_bar",
  :name => "auth_shared_login_bar",
  :insert_before => "li#search-bar",
  :partial => "spree/shared/login_bar",
  :disabled => false,
  :original => 'eb3fa668cd98b6a1c75c36420ef1b238a1fc55ad')

我还更新了 config/routes.rb 文件:

Rails.application.routes.draw do

  # This line mounts Spree's routes at the root of your application.
  # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
  # If you would like to change where this engine is mounted, simply change the :at option to something different.
  #
  # We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
  mount Spree::Core::Engine, at: '/'
        
        # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

        devise_scope :person do
        get '/login', :to => "devise/sessions#new"
        get '/signup', :to => "devise/registrations#new"
        delete '/logout', :to => "devise/sessions#destroy"
        end

end

我似乎找不到解决方法。

如果您的应用程序是新的或者您正在使用新的用户模型,那么使用 spree_auth_devise gem/extension 这将提供与所有 spree 版本兼容的所有用户级别身份验证。

您在 app/overrides/auth_login_bar.rboverride 文件告诉 Spree 将名为 spree/shared/login_bar 的局部视图插入导航栏。您是否在视图中创建了这个部分?

这是我的局部视图(用 HAML 编写),位于 spree/shared/_login_bar.html.haml

- if spree_current_user
  %li= link_to(Spree.t(:logout), destroy_spree_user_session_path, method: :delete)
- else
  %li= link_to(Spree.t(:login), login_path)
  %li= link_to(Spree.t(:signup), signup_path)

您也可以从第二行中删除 method: :delete 使其成为 get 请求,我认为这就是 Spree 现在的设置方式。