0
通過GET
請求檢查是否發送後續請求POST
並且不需要在第一個請求之後呈現任何東西。我使用render nothing: true
在我的控制器操作的基礎上,所以我不知道是什麼導致了ActionView::MissingTemplate at /able_to_claim
錯誤時,我給通過瀏覽器控制檯的要求:AJAX GET請求在Rails中沒有渲染視圖/ json
def able_to_claim
role, user_id = params[:role], params[:user_id]
if role == "Senior Editor" or role == "Admin"
return true
else
active_essays = 0
Claim.where(:user_id => user_id).each {|claim| active_essays += 1 if Essay.find(claim.essay_id).status != "Complete"}
if role == "Editor" and active_essays < 5
return true
elsif role == "Managing Editor" and active_essays < 15
return true
else
return false
end
end
render nothing: true
end
路線:get '/able_to_claim' => 'users#able_to_claim'
js文件:
response = $.ajax({
type: 'GET',
url : '/able_to_claim/?role=' + userRole + '&user_id=' + userId,
crossDomain: true,
contentType:'application/json; charset=utf-8',
dataType: 'json'
});
的UserRole和用戶id在application.html.erb
定義:
<%= javascript_tag "var userId = #{current_user.id};" if current_user %>
<%= javascript_tag "var userRole = '#{current_user.role}';" if current_user %>