gpt4 book ai didi

ruby-on-rails - AbstractController::ActionNotFound - 奇怪的错误

转载 作者:行者123 更新时间:2023-12-01 01:35:24 26 4
gpt4 key购买 nike

我遇到了一个非常奇怪的路由错误,在 Rails 3.2.11 中我似乎无法解决该错误

错误是:AbstractController::ActionNotFound(无法为 SubmissionsController 找到操作“bulk_submissions_url”)

我有一条如下所示的路线:

match 'submissions/bulk_submissions_url' => 'submissions#bulk_submissions_url', :as => 'bulk_submissions_url', :via => :post

SubmissionsController 如下所示:

class SubmissionsController < ApplicationController

...
def bulk_submissions_url
if signed_in?

#get the cert that the user has if they are returning to tutorial
if current_user.enrollments and current_user.enrollments.length > 0
@enrollment = current_user.enrollments.last
else
#handle this
end

@submission = Submission.create!(url: params[:url], description: "Please edit this description", work_type: "other", date_completed: DateTime.now.to_date)

if @submission.save
@enrollment.submissions << @submission
render :json => { success: true, submission_id: @submission.id }
else
render :json => { success: false }
end

end
end

我正在使用 jQuery 发出请求:

//save the submission
$.ajax({
type: 'POST',
url: '<%= bulk_submissions_url_path %>',
data: {url : $("#tutorial_add_work_url_input").val()},
dataType: 'json'
});

我有什么遗漏吗?

提前致谢!

最佳答案

您在名称中使用 _url 是有原因的吗?这可能会导致困惑,因为名为 my_route 的路由可以通过 my_route_path 和 my_route_url 等方法访问,但如果您将路由命名为 my_route_url,那么它应该由 my_route_url_path 和 my_route_url_url 访问,这是一团糟。

尝试这条路线:

match 'submissions/bulk_submissions' => 'submissions#bulk_submissions', :as => 'bulk_submissions', :via => :post

Controller :

class SubmissionsController < ApplicationController

def bulk_submissions
if signed_in?

#get the cert that the user has if they are returning to tutorial
if current_user.enrollments and current_user.enrollments.length > 0
@enrollment = current_user.enrollments.last
else
#handle this
end

@submission = Submission.create!(url: params[:url], description: "Please edit this description", work_type: "other", date_completed: DateTime.now.to_date)

if @submission.save
@enrollment.submissions << @submission
render :json => { success: true, submission_id: @submission.id }
else
render :json => { success: false }
end

end
end
end

和ajax

//save the submission
$.ajax({
type: 'POST',
url: '<%= bulk_submissions_path %>',
data: {url : $("#tutorial_add_work_url_input").val()},
dataType: 'json'
});

关于ruby-on-rails - AbstractController::ActionNotFound - 奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15148348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com