语法错误ruby on rails意外':',在调用render json时期待'}':

时间:2022-08-04 23:06:23

Error:

SyntaxError in UsersController#index
 /home/ubuntu/ruby/users/app/controllers/users_controller.rb:7: syntax error, unexpected ':', expecting '}'
      format.json{render json: UsersDatatable.new(view_context)}
                              ^

I am trying to get dataTables plugin to work with my rails application (railcast #340). I have poured over and over and have no clue where this error might be coming from. It does not look like it's any different from the code listed in http://railscasts.com/episodes/340-datatables?view=asciicast (except that I changed the name from Products to Users everywhere. I have completely hit a wall. My code seems to be identical in all but the name, and yet it doesn't work! (it worked before I tried to start setting up the AJAX part)

我正在尝试使用dataTables插件来使用我的rails应用程序(railcast#340)。我一遍又一遍地倾倒,并且不知道这个错误可能来自哪里。它看起来与http://railscasts.com/episodes/340-datatables?view=asciicast中列出的代码没有任何不同(除了我将名称从产品更改为用户到处。用户已经完全碰到了墙。除了名字之外,我的代码似乎完全相同,但它不起作用!(在我尝试开始设置AJAX部分之前它已经工作了)

EDIT: Originally I used 1.8.7 and rails (3.2.7), but then upgraded to ruby 1.9.3, so not sure why I am still getting that error

编辑:最初我使用1.8.7和rails(3.2.7),但后来升级到ruby 1.9.3,所以不知道为什么我仍然得到那个错误

1 个解决方案

#1


3  

If you're using ruby 1.8.7 then the syntax json: ... will not work.

如果您使用的是ruby 1.8.7,则语法json:...将无效。

This should work instead (as @Jérôme Boé pointed out)

这应该是有效的(正如@JérômeBoé指出的那样)

format.json { render :json => UsersDatatable.new(view_context) }

#1


3  

If you're using ruby 1.8.7 then the syntax json: ... will not work.

如果您使用的是ruby 1.8.7,则语法json:...将无效。

This should work instead (as @Jérôme Boé pointed out)

这应该是有效的(正如@JérômeBoé指出的那样)

format.json { render :json => UsersDatatable.new(view_context) }