我得到的错误是:找不到没有 ID 的用户
当他们登录时,我实际上是在尝试让用户的课程在他们的主页上列出。但是我无法让@用户在控制器中正常工作,我相信这是一个路由错误,但不确定
静态页面控制器
class StaticPagesController < ApplicationController
def home
@user = User.find(params[:id]) <<<here is the problem
@courses = @user.courses
end
end
查看部分
<div class="row">
<div class="span8">
<% if @courses.any? %>
<ul class="courses">
<%- @courses.each do |course| %>
<%= link_to course.title, course_path(course) %>
<%- end%>
</ul>
<% end %>
</div>
</div>
路由.rb
Serenity::Application.routes.draw do
root to: 'static_pages#home'
# match '/signup', to: 'users#new'
# match '/signin', to: 'sessions#new'
# match '/signout', to: 'sessions#destroy', via: :delete
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
ActiveAdmin.routes(self)
resources :users do
member do
get :courses
end
end
resources :courses
resources :assignments, only: [:create, :destroy]