继续获取未定义的方法错误' user_url

时间:2015-01-02 21:52:42

标签: ruby-on-rails session devise

我在应用程序中使用设计,并且我一直收到一个未定义的方法错误,说user_url。这是我有的请帮我解决这个问题

这是错误:

NoMethodError in Users::SessionsController#create
undefined method `user_url' for #<Users::SessionsController:0xa33291c>

Rails.root: /home/vagrant/code/AppSample

Application Trace | Framework Trace | Full Trace
actionpack (4.0.10) lib/action_dispatch/routing/polymorphic_routes.rb:129:in `polymorphic_url'
actionpack (4.0.10) lib/action_dispatch/routing/url_for.rb:159:in `url_for'
actionpack (4.0.10) lib/action_controller/metal/redirecting.rb:101:in `_compute_redirect_to_location'
...

这是User session_controller:

class Users::SessionsController <
Devise::SessionsController

  def after_sign_in_path_for(resource)
    @tenants_dashboard_path
  end


  def create
    user = User.find_by(:email => params[:email])
    manager = Manager.find_by(:email => (params[:email])
    if user && tenant.authenticate (params[:password])
      session[:tenant_id] = tenant.id
      redirect_to users_main_url, notice: "You are Logged in!"
    elsif
    manager && manager.authenticate(params[:password])
      session[:manager_id] = manager.id
      return managers_main_url, notice: "You are Logged in!"
    else
      flash.now.alert = "Email or password is invalid."
    end
end

错误是当我尝试将用户重定向到仪表板页面时。这是我的app控制器中的登录后方法

 def after_sign_in_path_for(resource)
    if resource.is_a?(Users)
      return users_dashboard_path, notice: "You are Logged in!"
    elsif resource.is_a?(Managers)
      return managers_dashboard_path, notice: "You are Logged in!"
    end
  end

这是路线:

    devise_for :users, controllers: {registrations: "users/registrations", sessions: "users/sessions" }
    devise_for :managers, controllers: {registrations: "managers/registrations", sessions: "managers/sessions" }
    resources :reports
    resource :dashboard

  get "/managers/why_use_us" => "managers/landing#index", as: :managers_why
  get "/users/why_choose_us" => "users/landing#index", as: :tenants_why

  get "/managers/LeaseDefend_dashboard" => "managers/dashboard#index", as: :managers_main
  get "/users/LeaseDefend_dashboard" => "users/dashboard#index", as: :tenants_main

  namespace :users do
    get 'landing', to: 'landing#index'
    get 'dashboard', to: 'dashboard#index'
    resources :landing, :dashboard
  end''

我无法弄清楚要改变什么我改变了资源以匹配用户文件夹的名称,即Managers&amp;租户

1 个答案:

答案 0 :(得分:2)

我更改了after_sign_in_path方法并在每个控制器中放置了一个单独的方法,因为有不同的用户