Search code examples
ruby-on-railsspreespree-auth-devise

having problems with the login link using Spree


So I tried to add the login link on my Spree Rails app by following the documentation in http://guides.spreecommerce.org/developer/authentication.html However I haven't been able to get the link on my app.enter image description here

I created app/overrides/auth_login_bar.rb file following the documentation adding the following code to the file.

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')

I also updated config/routes.rb file:

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

I don't seem to find how to fix it.


Solution

  • Your override file at app/overrides/auth_login_bar.rb is telling Spree to insert a partial view called spree/shared/login_bar into the nav bar. Did you create this partial in your views?

    Here's my partial view (written in HAML), located at 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)
    

    You could also remove the method: :delete from the second line to make it a get request, which I think is how Spree is set up now.