ruby on rails - ActionController::InvalidCrossOriginRequest exception due to bingbots -
i have rails applications loading comments using ajax after page load.
class commentscontroller < applicationcontroller respond_to :js def index @comments = comments.all respond_with @comments end end
it working expected. bingbot trying access url leads
an actioncontroller::invalidcrossoriginrequest occurred in comments#index: security warning: embedded tag on site requested protected javascript. if know you're doing, go ahead , disable forgery protection on action permit cross-origin javascript embedding.
like coming url's responding js format.
i know rack-cors, allowing cross side script access, here not.
app/views/comments/index.js.erb
$('.comments_container').html("<%=j render 'comments' %>");
comments.js
jquery(function() { return $.ajax({ url: $('.comments_container').data('url')({ datatype: "script" }) }); });
assuming need cors(cross-origin resource sharing), getting error because cors policy default "denying" every direct xhr access.
you can use rack-cors gem https://github.com/cyu/rack-cors avoid this. hope help!
Comments
Post a Comment