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 %>