Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top