1

dashboards#show如果我按原样使用以下代码Couldn't find Dashboard without an IDuser_dashboard_path(current_user, current_user.dashboard)rb)。

我想我需要将用户传递到设置根路径的代码块中,但我不确定这将如何完成。

有小费吗?

这是我的整个 routes.rb 文件:

MyApp::Application.routes.draw do
  resources :users do
    resources :dashboards, only: [:show, :edit, :update, :destroy]
  end

  authenticated :user do
    # Instead of the show action, I want to go to user_dashboard which is
    # GET    /users/:user_id/dashboards/:id(.:format)      dashboards#show
    root :to => "dashboards#show", as: :authenticated_root
  end

  root :to => "home#index"
  devise_for :users, :controllers => { :registrations => :registrations }

end
4

1 回答 1

2

选项 1:
在您的仪表板控制器中,更改为:

@user = current_user
@dashboard = current_user.dashboard

这也将阻止用户查看其他用户的仪表板。

选项 2:
现在,如果用户可以正常查看其他用户的仪表板,则更改您的路线:

root :to => "dashboards#find", as: :authenticated_root

在您的仪表板控制器中:

def find
  redirect_to user_dashboard_path(current_user, current_user.dashboard)
end
于 2013-07-02T13:42:16.827 回答