我正面临一个非常奇怪的路由错误,我似乎无法在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'
});
我有什么遗失的吗?
提前致谢!
答案 0 :(得分:1)
您是否有理由在姓名上使用_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
控制器:
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'
});