0

アプリでdeviseとcancanを使用しています。どちらも機能しています。

モデルがあり、(足場を使用して)という新しいモデルをUser追加しました。Purchase

購入モデルが追加される前は、ダッシュボード コントローラーもあり(現時点では 1 つのページしか表示されませんdashboard#show)、ログイン後に読み込まれるページです。localhost:3000/dashboard

ユーザーがログインしていないときは、アクセスできますlocalhost:3000/purchases。しかし、ユーザーがログインしているときはできません。アクセスできますpurchase/1が、できません/purchases

ここで何が起こっているのか分かりますか?それが私に与えるエラーは

"一致するルートがありません {:action="show", :controller="dashboard"}"

ダッシュボード コントローラー

class DashboardController < ApplicationController
    def show
        @user = User.find(params[:id])
        authorize! :read, @user
    end

end

Routes.rb

App::Application.routes.draw do
  root :to => 'static_pages#index'
  match '/about', :to => 'static_pages#about'
  match '/error', :to => 'static_pages#error'
  devise_for :users

  resources :users

  resources :dashboard

  resource :visitors, :only => :create # POST to visitor_path to create a visitor

  resources :purchases

レーキルート

                    root        /                              static_pages#index
                   about        /about(.:format)               static_pages#about
                   error        /error(.:format)               static_pages#error
        new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
            user_session POST   /users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
       user_registration POST   /users(.:format)               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                         PUT    /users(.:format)               devise/registrations#update
                         DELETE /users(.:format)               devise/registrations#destroy
                   users GET    /users(.:format)               users#index
                         POST   /users(.:format)               users#create
                new_user GET    /users/new(.:format)           users#new
               edit_user GET    /users/:id/edit(.:format)      users#edit
                    user GET    /users/:id(.:format)           users#show
                         PUT    /users/:id(.:format)           users#update
                         DELETE /users/:id(.:format)           users#destroy
         dashboard_index GET    /dashboard(.:format)           dashboard#index
                         POST   /dashboard(.:format)           dashboard#create
           new_dashboard GET    /dashboard/new(.:format)       dashboard#new
          edit_dashboard GET    /dashboard/:id/edit(.:format)  dashboard#edit
               dashboard GET    /dashboard/:id(.:format)       dashboard#show
                         PUT    /dashboard/:id(.:format)       dashboard#update
                         DELETE /dashboard/:id(.:format)       dashboard#destroy
                visitors POST   /visitors(.:format)            visitors#create
               purchases GET    /purchases(.:format)           purchases#index
                         POST   /purchases(.:format)           purchases#create
            new_purchase GET    /purchases/new(.:format)       purchases#new
           edit_purchase GET    /purchases/:id/edit(.:format)  purchases#edit
                purchase GET    /purchases/:id(.:format)       purchases#show
                         PUT    /purchases/:id(.:format)       purchases#update
                         DELETE /purchases/:id(.:format)       purchases#destroy
4

2 に答える 2

0

単数はでなければなりませんresource、そうでなければresources

resource :dashboard
resource :visitor, :only => :create

また

resources :dashboards

タスクが何であるかに応じて

于 2013-01-11T08:03:13.023 に答える
0

ダッシュボードは単一のリソースであるため、次のように設定する必要があります。

resource :dashboard

それはリソース単数形です。

私の推測では、ログインしたユーザーの購入ページには のようなものがあると思いますがlink_to "Dashboard", dashboard_path、リソースが設定されていても、show アクションは常に ID を必要とします。提供していないため、ルーティング例外が発生します。

ここで特異なリソースについて少し見つけることができます: http://guides.rubyonrails.org/routing.html#singular-resources

于 2013-01-11T07:56:41.770 に答える