显示已预订用户的一般列表

时间:2017-03-22 19:17:29

标签: ruby-on-rails ruby model-view-controller

我创建了一个用户可以预订一小时培训的应用程序。我想给管理员用户提供在每个培训时间内查看预订用户的一般列表的选项。

我试图创建这个索引,但它给了我以下错误:

  训练中的 ActionController :: UrlGenerationError #index

     

没有路线   匹配{:action =>" index",:controller =>"预订",:training_id => nil}   缺少必需的密钥:[:training_id]

我试图在训练索引处创建此按钮,如下所示:

培训index.html.erb查看:

<h1>Hours</h1>

<ul class="trainings">
  <% @trainings.each do |training| %>
  <li>
    <%= link_to training.hour, training_path(training) %>
  </li>
  <% end %>
</ul>

<%= render 'bookings/general_list' if logged_in? %>

_general_list.html.erb查看:

<ul class="bookings">
<% @trainings.each do |training| %>
<%= link_to "General list", training_bookings_path(@training), class: "btn btn-primary"  %>    
<% end %>
</ul>

我现在想如何完成这项工作,我认为我的想法不起作用。

my routes.rb:

Rails.application.routes.draw do

  root 'static_pages#home'
  get    '/signup',               to: 'users#new'
  get    '/contact',              to: 'static_pages#contact'
  get    '/about',                to: 'static_pages#about'
  get    '/login',                to: 'sessions#new'
  post   '/login',                to: 'sessions#create'
  delete '/logout',               to: 'sessions#destroy'


  resources :account_activations, only: [:edit]
  resources :password_resets,     only: [:new, :create, :edit, :update]
  resources :users
  resources :trainings do
    resources :bookings
  end
end

rake routes命令:

                 Prefix Verb   URI Pattern                                         Controller#Action
                   root GET    /                                                   static_pages#home
                 signup GET    /signup(.:format)                                   users#new
                contact GET    /contact(.:format)                                  static_pages#contact
                  about GET    /about(.:format)                                    static_pages#about
                  login GET    /login(.:format)                                    sessions#new
                        POST   /login(.:format)                                    sessions#create
                 logout DELETE /logout(.:format)                                   sessions#destroy
edit_account_activation GET    /account_activations/:id/edit(.:format)             account_activations#edit
        password_resets POST   /password_resets(.:format)                          password_resets#create
     new_password_reset GET    /password_resets/new(.:format)                      password_resets#new
    edit_password_reset GET    /password_resets/:id/edit(.:format)                 password_resets#edit
         password_reset PATCH  /password_resets/:id(.:format)                      password_resets#update
                        PUT    /password_resets/:id(.:format)                      password_resets#update
                  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
                        PATCH  /users/:id(.:format)                                users#update
                        PUT    /users/:id(.:format)                                users#update
                        DELETE /users/:id(.:format)                                users#destroy
      training_bookings GET    /trainings/:training_id/bookings(.:format)          bookings#index
                        POST   /trainings/:training_id/bookings(.:format)          bookings#create
   new_training_booking GET    /trainings/:training_id/bookings/new(.:format)      bookings#new
  edit_training_booking GET    /trainings/:training_id/bookings/:id/edit(.:format) bookings#edit
       training_booking GET    /trainings/:training_id/bookings/:id(.:format)      bookings#show
                        PATCH  /trainings/:training_id/bookings/:id(.:format)      bookings#update
                        PUT    /trainings/:training_id/bookings/:id(.:format)      bookings#update
                        DELETE /trainings/:training_id/bookings/:id(.:format)      bookings#destroy
              trainings GET    /trainings(.:format)                                trainings#index
                        POST   /trainings(.:format)                                trainings#create
           new_training GET    /trainings/new(.:format)                            trainings#new
          edit_training GET    /trainings/:id/edit(.:format)                       trainings#edit
               training GET    /trainings/:id(.:format)                            trainings#show
                        PATCH  /trainings/:id(.:format)                            trainings#update
                        PUT    /trainings/:id(.:format)                            trainings#update
                        DELETE /trainings/:id(.:format)                            trainings#destroy

感谢。

1 个答案:

答案 0 :(得分:0)

_general_list.html.erb中,您应该更改@training

training