当我运行仅执行get :index
的测试时,我收到此错误。这是测试代码:
class SubmissionsControllerTest < ActionController::TestCase
setup do
@submission = submissions(:one)
end
test "should get index" do
get :index
assert_response :redirect
# assert_not_nil assigns(:submissions)
end
我在我的routes.rb文件中设置了这个控制器的路由:
resources :courses do
resources :assignments do
get 'export', :controller => 'assignments', :action => 'export'
resources :memberships
resources :submissions do
resources :evaluations do
delete 'destroy', controller: 'reviews', action: 'destroy'
end
end
resources :questions do
resources :responses
resources :scales
end
resources :reviews do
get :assign_reviews, :on => :collection
post :edit_review, :on => :collection
end
end
end
此外,这是我在运行rake路线时获取提交路线的原因:
course_assignment_submissions GET /courses/:course_id/assignments/:assignment_id/submissions(.:format) submissions#index
POST /courses/:course_id/assignments/:assignment_id/submissions(.:format) submissions#create
new_course_assignment_submission GET /courses/:course_id/assignments/:assignment_id/submissions/new(.:format) submissions#new
edit_course_assignment_submission GET /courses/:course_id/assignments/:assignment_id/submissions/:id/edit(.:format) submissions#edit
course_assignment_submission GET /courses/:course_id/assignments/:assignment_id/submissions/:id(.:format) submissions#show
PUT /courses/:course_id/assignments/:assignment_id/submissions/:id(.:format) submissions#update
DELETE /courses/:course_id/assignments/:assignment_id/submissions/:id(.:format) submissions#destroy
这是我的索引操作代码:
def index
if !current_user.instructor?(@course)
raise CanCan::AccessDenied.new("Not authorized!")
end
registrations = @course.registrations
@students = registrations.select{|r| !r.user.pseudo or @assignment.memberships.any?{|m| m.pseudo_user_id == r.user_id } }.map{|r| r.user }
respond_to do |format|
format.html # index.html.erb
format.json { render json: @students }
end
end
有谁知道这个错误可能来自哪里?
答案 0 :(得分:0)
由于您的submissions
控制器嵌套在assignments
和assignments
嵌入courses
,您必须将:assignment_id
和:course_id
传递给您得到请求。
例如:
get :index, course_id: your_course, assignment_id: your_assignment