0

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)

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

StanM
  • 827
  • 4
  • 12
  • 33

1 Answers1

3

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

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

format.json { render :json => UsersDatatable.new(view_context) }
Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82
  • 1
    I put in comment to Jerome, also I installed rvm (after the above) but the changes I make with RVM don't seem to stick when I do 'ruby -v', what am i doing wrong? – StanM Sep 11 '12 at 11:51
  • Try typing: `which ruby` and see what that gives you. Probably you're running the version of ruby installed on the system. I don't use rvm (anymore) but I believe you can change the version you're using with: `rvm use 1.9.3` (or whatever version you want to use). – Chris Salzberg Sep 11 '12 at 12:53
  • Anyway the question of how to get rvm to use the right version of ruby is not the one you asked here. Clearly the problem is with the ruby version. If you have issues working with rvm or installing a particular version of ruby you should post a separate question (and mark this one as the answer to this question). – Chris Salzberg Sep 11 '12 at 12:54
  • I upgraded it and 'which ruby' gives me ruby-1.9.3-p194/bin/ruby, but when I run the server I still get the above error. It certainly seems that the ruby version is to blame, but i'm not sure if that's the case now – StanM Sep 11 '12 at 14:31
  • Ok first of all, assuming you're still running 1.8.7 for whatever reason, the fix (`:json =>`) should work. You say it doesn't. What is the error you get? – Chris Salzberg Sep 11 '12 at 22:00
  • I think because i used the scaffolding of 1.9.3 it started complaining about those. I fixed the problem where it was running ruby 1.8.7 so it's resolved now. – StanM Sep 12 '12 at 16:11