2012-10-29 67 views
1

但我想它匹配[POST] “/ student_tests/1 /上传”没有路由匹配[POST] “/student_tests/upload.1”

在我已经添加

resources :student_tests do 
    member do 
     post 'upload' 
    end 
end 
的routes.rb中

在我添加了一些

def upload 
    render :upload 
end 

在student_test

<%= link_to "| Upload Scaled Scores", upload_student_test_path(test), method: :edit%> 
索引页面的students_test_controller

这里测试的student_test

的目的是通过使用机架式路线

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

。我在什么错误,其“/student_tests/upload.1”搜索我希望它寻找“/ student_tests/1 /上传”(在这里是1是学生的考试的id)

+1

你能粘贴你用来生成超级引用的link_to代码吗? –

回答

0

我觉得你用你的路由方式可以进行如下更改:

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

我不明白你为什么要在控制器的操作之前需要ID。您可以更改路由格式并相应地访问ID。

由于我发现很难理解你的问题,你构思这个问题的方式可能会更好。在这里回答我的理解。

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方法。