0

Good day! I'm trying to implement ajax in my rails test app. my controller code app/controllers/admin/data

class Admin::DataController < ApplicationController
...  
  def ajax
   if  params[:ajax] == 'list'
 @responce = Admin::Datum.all
   else
     @responce ={error: true}
   end
    respond_to do |format|
      # format.html { redirect_to @user }
      # format.js
      format.json { render json: @responce }
    end
  end
    end

index.js.erb

alert('1');
$.post('/admin/data/ajax',{ajax:'list'},function(responce){
alert('2');
console.log(responce);
}
);

could you help me in determining the url that i've to use in ajax to access ajax method? or any other help is very welcome!

Update 1 Updated initial code to represent more complex problem

4

1 に答える 1

0

I added to routes.rb

 match 'admin/data/ajax' => 'Admin::Data#ajax'

could be any url, it's what you write in your jquery. And it works!

于 2012-08-17T13:02:45.823 に答える