dimanche 21 juin 2015

Rails Devise Routes: If user signed in, point to index. Else, point to new user session

Pretty simple question, but I can't seem to find the answer with a good ole fashioned Google.

The error:

undefined method `user_signed_in?' for #<ActionDispatch::Routing::Mapper:0x007fc6369320e8> (NoMethodError)

Server won't even start.

My code:

Rails.application.routes.draw do

devise_for :users, :path_prefix => 'u'
resources :users

  devise_scope :user do
    get "login", to: "devise/sessions#new", as: :login
    get 'logout', to: 'devise/sessions#destroy', as: :logout
    get 'user/edit', to: 'devise/registrations#edit', as: :change_password
  end

  resources :apps do
    resources :elements, controller: 'apps/elements'
  end

  resources :elements do
      resources :features, except: [:index], controller: 'apps/elements/features'
  end

if user_signed_in?
  root to: 'apps#index'
else
devise_scope :user do
  root to: 'devise/sessions#new'
end
end

end

What's the best way to go about making this work? I'm hesitant to try to work around it and make the site vulnerable, being a new RoR user. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire