【发布时间】:2013-02-20 08:41:50
【问题描述】:
我正在通过 twitter 引导模式窗口传递一个 ajax 调用来更新我的应用程序中的数据。 ajax代码如下:
$(document).ready(function(){
var link=$('#link_hash').val();
$("#update_link").click(function(){
console.log("I'm here");
$.ajax({
url: "profiles/update_link",
type: "POST",
dataType: "html",
data: {link: link,data: $('#link_hash').val() },
success: function(data) {
// some code
},
error: function(data1) {
// some code
}
});
});
});
我已修改 route.rb 文件以使其与我的控制器“update_link”方法相匹配。 我的方法中的代码如下:-
def update_link
@link=Link.find_by_link(params[:link])
@tlink=Link.find_by_link(params[:data])
logger.info "=========kkkkkkkkkkkkkk=================================#{@link.inspect}"
logger.info "=========kkkkkkkkkkkkkk=================================#{@tlink.inspect}"
logger.info "=========kkkkkkkkkkkkkk=================================#{params.inspect}"
respond_to do |format|
if @tlink.nil?
@link.update_attributes(:link => params[:data])
...some code....
else
...some code...
end
end
end
end
所以在服务器日志中显示 -
Started POST "/profiles/update_link" for 127.0.0.1 at 2013-02-20 12:08:20 +0530
Processing by ProfilesController#update_link as HTML
Parameters: {"link"=>"9bfzjp", "data"=>"9bfzjpaaa"}
WARNING: Can't verify CSRF token authenticity
Completed 401 Unauthorized in 6ms
很明显 "logger.info" 没有出现...现在搜索后我能够解决 WARNING 但仍然存在 401...如何解决这个问题?? p>
提前谢谢....
【问题讨论】:
标签: ruby ruby-on-rails-3 jquery