views:

279

answers:

2

I am trying to reuse some code from another rails application I had worked on earlier. I copied over all the models / views / controller / migrations and ran rake db:create and migrate. Now when I try to run the application the initial page for this view (the one that has the list edit/delete) loads fine and shows there are 0 records. When I click new, however, it displays an error message on a bit of code created by the scaffolding in my other application...

<%= link_to 'New comment', new_comment_path %>

undefined local variable or method `new_comment_path' for #<ActionView::Base:0xb67c9690>

Should I be able to reuse this code or is their something else I need to do to make sure that I have everything moved over. I tried using grep to find where the 'new_comment_path' was being defined in my other project and I only saw it used in a similar context to what is listed above. Any help would be appreciated.

+6  A: 

This error shows that you are missing routes.

Check in the conf/routes.rb file in the App you're copying from.

Most probably all you need to do is add

map.resources :comments

to your routes.rb

And add that for all the controllers that you copied.

Jimmy Stenke
Thank you that definitely fixed the problem.
Ryan Lanciaux
+1  A: 

If you have time, or expect to do this again, you might consider making the reuse candidates into a plugin, or use the engines feature in 2.3 (or install the rails_engines plugin for slightly older versions)

Mike Woodhouse
Thanks. I'll have to look into that a bit more. These are my first couple 'real' rails apps I'm working on.
Ryan Lanciaux