Search code examples
ruby-on-railsrubyruby-on-rails-4scaffoldingruby-on-rails-4.1

Rails Scaffolding [controller]#new crashing server


Continuing with my Rails Library Management App, I learnt about scaffolds and thought that it would give me ample framework to re-work upon. The thing is, that although scaffolds are being generated and everything, they aren't working properly. Rather, they aren't working at all.

When I access to http://localhost/[controller-name], It shoots up a webpage that says Listing [controller-name] all fine. But when i click on new button or navigate to http://localhost/[controller-name]/new, the server crashes without an error.

P.S.

While trying things, I noticed that although,

$ rails generate scaffold person name:string identity:integer DOB:date

works just fine,

$ rails generate scaffold student name:string id_number:integer class:integer section:string issued:date returned:date fine:integer reissued:date

doesn't?

P.P.S.

The real problem is, accessing the action "student#new" does not only NOT work, but also crashes my server (yeah no exiting WEBrick). All I can provide are the messages that appear at the end:

Started GET "/assets/students.css?body=1" for 127.0.0.1 at 2015-08-05 12:20:19 +0530


Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2015-08-05 12:20:19 +0530


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2015-08-05 12:20:19 +0530


Started GET "/students/new" for 127.0.0.1 at 2015-08-05 12:20:21 +0530
Processing by StudentsController#new as HTML

Solution

  • class is a keyword in Ruby, so using that as a column name isn't a great idea. On this line:

    $ rails generate scaffold student name:string id_number:integer class:integer section:string issued:date returned:date fine:integer reissued:date

    change class:integer to kind:integer and it should work.