1

但我希望它匹配 [POST] "/student_tests/1/upload"

IN 我添加的 routes.rb

resources :student_tests do
    member do
      post 'upload'
    end
end

在 student_test_controller 我添加了

def upload
    render :upload
end

在 student_test 的索引页中

<%= link_to "| Upload Scaled Scores", upload_student_test_path(test), method: :edit%>

其中 test 是 student_test 的一个对象

通过使用机架路由

upload_student_test POST  /student_tests/:id/upload(.:format)   student_tests#upload

我犯了什么错误,它搜索“/student_tests/upload.1”我希望它寻找“/student_tests/1/upload”(这里1是学生测试的ID)

4

2 回答 2

1

您在路线中创建了一个“POST”成员操作,但您以错误的方式链接到它:

<%= link_to "| Upload Scaled Scores", upload_student_test_path(test), method: :edit%>

实际上应该是这样的:

<%= link_to "| Upload Scaled Scores", upload_student_test_path(test), method: :post %>

然而,这可能不是传统的铁轨布线方式。如果您只想在那里呈现视图,那么一种GET方法将是最合适的。当您上传文件时,您可以使用POST您在此处尝试的方法。

于 2012-10-29T13:05:40.123 回答
0

我认为您使用路线的方式可以更改如下:

match ':controller(/:action(/:id(.:format)))' 

我不明白您在控制器操作之前需要 ID 的原因。您可以更改路线格式并相应地访问 ID。

您提出问题的方式可能会更好,因为我发现很难理解您的问题。在这里用我的理解回答。

于 2012-10-29T12:58:35.833 回答