0

i have function get_rule(rulename) in controller/team/index_controller.rb which is returnig a map and i have javascript from which i want to call this function . Right now i am doing an ajax call from this script

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');

          }
        });

my 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

please provide me some suggesstion or code so that i can make a call . i spent whole day on single but don't want to waste more time on this.And i want the map returning from controller function in a variable i.e. i want response of ajax into a variable

3
  • please check your routes, for example running "rake routes" on command line or browse localhost:3000/rails/info/routes More info: guides.rubyonrails.org/… I think your route can be shorter like ends with: ...team/index/get_rule + pass your attributes in jQuery.ajax's data variable. More info: api.jquery.com/jquery.ajax Commented Apr 6, 2015 at 12:39
  • i think problem is in query not in routes . provide me some method to do so Commented Apr 6, 2015 at 12:46
  • no.. It's probably in the routes Commented Apr 6, 2015 at 12:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.