當我運行一個簡單的測試時出現這個錯誤get :index
。下面是測試代碼:沒有路線匹配{:controller =>「提交」}
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
而且,這是我得到的路線意見書當我運行耙路線:
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
有誰知道這個錯誤可能來自哪裏?
您可以將您的測試代碼? –
剛剛添加了我的測試代碼 – Kevin
您能否包含您的測試代碼的類(例如,class SubmissionsController