我在controller / team / index_controller.rb中有函数get_rule(rulename),它返回一个地图,我有javascript,我想从中调用此函数。现在我正在从这个脚本做一个ajax调用
jQuery.ajax({
url: "<%= Rails.configuration.url_prefix %>/team/index/get_rule_attribute_values",
type: "POST",
dataType : "json",
success: function(){
console.log("success");
},
error: function(jqXHR, textStatus,errorThrown){
var requestResponse = {
httpStatus: jqXHR.status,
error:jqXHR.statusText,
};
console.log("requestResponse");
// Notify the user so he might not wonder.
alert('Something went wrong, Please try again');
// Report it back for fixing it
// Only for debuggify users
var ajaxErrors = debuggify.Logger.get('ajax_errors');
ajaxErrors.attach(requestResponse);
ajaxErrors.error('Caught ajax error');
}
});
我的getrule func
def getrule(rule_attribute_name)
# rule_attr_value = RuleAttribute.get_rule_attributes rule_attribute_name
# rule_attribute_values_hash = JSON.parse(rule_attr_value)
# rule_attr_values = rule_attribute_values_hash["rule_attribute_values"]
# rule_attribute_values = Hash.new
# rule_attr_values.each do |value|
# rule_attribute_values.store(value["internal_name"],value["display_name"])
# end
respond_to do |format|
format.json {render :json =>{:error => false, :message => "test"}}
return rule_attribute_values
end
请提供一些建议或代码,以便我可以拨打电话。我花了整整一天单身,但不想浪费更多的时间在这上面。我希望地图从控制器功能返回一个变量,即我希望ajax响应变量