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 に答える