Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming controllers in Rails and cleaning out generated content

I was following along with the railscast regarding the restful_authentication plugin.

He recommended running the command:

script/generate authenticated user session

Which I did, and everything generated "fine", but then sessions wouldn't work. Checking the site again, he mentions a naming standard and listed updated code which stated:

script/generate authenticated user sessions

With sessions being pluralized.

So now I have session_controller.rb with a SessionController in it, but I guess by naming standards, it is looking for SessionsController, causing the code to fail out with the error "NameError in SessionsController#create "

I see the problem, which is pretty obvious, but what I don't know is, how do I fix this without regenerating the content? Is there a way to reverse the generation process to clear out all changes made by the generation?

I tried just renaming the files to sessions_controller with e SessionsController class, but that failed.

While writing this, I solved my own problem. I had to rename session to sessions in the routes file as a map.resource and rename the view directory from session to sessions, and update session_path in the html.erb file to sessions_path.

So I solved my problem, but my answer regarding removing generated content still remains. Is it possible to ungenerate content?

like image 376
scubabbl Avatar asked Sep 18 '08 02:09

scubabbl


2 Answers

Actually, script/destroy works for any generator - generators work by reading a script of sorts on what files to create; script/destroy just reads that script in reverse and removes all the files created, as long as you give it the same arguments you passed to script/generate.

To sum up: script/destroy authenticated user session would have removed all the generated files for you, after which you could have run script/generate user sessions without a problem.

like image 160
Ben Scofield Avatar answered Sep 20 '22 12:09

Ben Scofield


I've never tried script/destroy, but if you're reverting changes that you just made, the generate command should give you a list of files added and changes made. If you're using a version control system of some sort, running status/diff might help as well.

like image 35
Misplaced Avatar answered Sep 21 '22 12:09

Misplaced