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