[英]rails and ajax request 404 error
I have this error on my rails logs : 我在rails日志中遇到此错误:
Completed 404 Not Found in 11ms
** [Raven] User excluded error: #<ActionController::RoutingError: Not Found>
ActionController::RoutingError (Not Found):
app/controllers/schools_controller.rb:6:in `common_content'
I don't understand why, here is the code : 我不明白为什么,这是代码:
Show.html.erb Show.html.erb
<%= link_to "Vérifiés (#{@count_verified})", rate_verified_path, remote: true %>
routes.rb 的routes.rb
get '/rate_verified' => 'schools#verified_rating'
schools_controller.rb schools_controller.rb
before_filter :common_content, :only => [:show, :verified_rating]
def verified_rating
@selected = @ratings.where(:verified => true)
respond_to do |format|
format.js
end
end
verified_rating.js.erb verified_rating.js.erb
$('#verifie').html("<%= escape_javascript render(:partial => 'rating') %>");
Does someone could help me ? 有人可以帮助我吗?
EDIT 编辑
the common_content method : common_content方法:
def common_content
@school = School.where(city_namespace: params[:city], title_namespace: params[:title]).first || raise(ActionController::RoutingError.new('Not Found'))
@rating = Rating.new(params[:rating])
@rating.school_id = @school.id
@ratings = @school.ratings.desc(:created_at)
end
In first line of common_content
method, we can see: 在
common_content
方法的第一行中,我们可以看到:
School.where(city_namespace: params[:city], title_namespace: params[:title]).first || raise(ActionController::RoutingError.new('Not Found'))
Because the first part (before ||
) of that code returns nil
the second part is executed, which is: 因为该代码的第一部分(在
||
之前)返回nil
所以第二部分将被执行,即:
raise(ActionController::RoutingError.new('Not Found')
So the 404 is raised because no School
record was found. 由于未找到
School
记录,因此引发404。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.