Search code examples
ruby-on-railsredmineredmine-plugins

user session getting expire on ajax call in rails 2


I am working on redmine in rails 2, In my erb file i have one javascript function

function getLeaveTypeQuota()
    {
       var selected_leave_type_id = jQuery("#leave_type").val()
       jQuery.post(
                "getUserLeaveQuota",
                { leave_type_id: selected_leave_type_id },
                function(data) {
                    alert(data);
                }

        );
    }

In controller i am makeing a query to get quota of loggined user, using

@user_leave_record = UserLeaveRecord.find(:first,:conditions => {:group_detail_id => params[:leave_type_id], :user_id => session[:user_id]})

But i am getting nill in session[:user_id], but i am loggined. After ajax call i automatically log out. I dont know why it is happening. Kindly help me out. Thanks


Solution

  • If you enabled protect_from_forgery in app/controllers/application_controller.rb, you'll need to include authenticity_token in the data being posted. Please try to disable protect_from_forgery or add authenticity_token to the data being posted.