Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Rails error "syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('"

I am trying to migrate subject_id and course_id to the users table by typing:

rails generate migration add_course_id_and_subject_id_to_users course_id:integer, subject_id:integer

However, it results in the error:

_add_course_id_and_subject_id_to_users.rb:4: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('

Not sure why this is happening.

like image 731
achilles77 Avatar asked Jun 14 '14 20:06

achilles77


1 Answers

This is shell syntax, not Ruby syntax, so you need to drop the comma between you attribute defs:

rails generate migration add_course_id_and_subject_id_to_users course_id:integer subject_id:integer

With the comma, you're trying to add two fields, "course_id:integer," (comma!) and "subject_id:integer" with the types "integer," (comma!) and "integer", respectively.

Somewhere along the road, the generated Ruby code will have that syntax error and raise the exception.

like image 119
awendt Avatar answered Oct 24 '22 02:10

awendt