从ajax调用的Application Controller方法

时间:2014-08-27 16:47:51

标签: ruby-on-rails ajax

我的应用程序控制器中有一个方法。

def session_selected(id)
  session[:selected] = [] if session[:selected].blank?
  if session[:selected].include?(id)
    session[:selected].delete(id)
  else
    session[:selected] << id
  end
end

我从.js文件中调用它

function check_set(id){
  $.ajax({url: 'session_selected',
  data: {id: id},
  method: 'get'});
  window.location.reload();
}

该方法似乎从来没有看到id来自params ......

Started GET "/session_selected?id=5" for 127.0.0.1 at 2014-08-27 10:36:45 -0700
Processing by ApplicationController#session_selected as */*
  Parameters: {"id"=>"5"}
Completed 500 Internal Server Error in 1ms

ArgumentError - wrong number of arguments (0 for 1):

此外,有什么好的资源吗?

1 个答案:

答案 0 :(得分:0)

谢谢大家的帮助

应用程序控制器

def session_selected()
  id = params[:id]
  session[:selected] = [] if session[:selected].blank?
  if session[:selected].include?(id)
    session[:selected].delete(id)
  else
    session[:selected] << id
  end
end