How to fix undefined method error with nested resources in rails app? -


i error saying "undefined method `verses' nil:nilclass" when visit

/books/1/chapters/1/verses/new 

my routes.rb:

resources :books   resources :chapters     resources :verses   end end 

verse_controller.rb:

class versescontroller < applicationcontroller     before_filter :find_book     before_filter :find_chapter, :only => [:show, :edit, :update, :destroy]      def new         @verse = @chapter.verses.build     end       private     def find_book         @book = book.find(params[:book_id])     end      def find_chapter         @chapter = chapter.find(params[:chapter_id])     end  end 

any adviceo on how fix this?

the problem @ before_filter

before_filter :find_chapter, :only => [:show, :edit, :update, :destroy] 

now hit new, there no before_filter triggered new, @chapter nil.

solution: add :new array.

update way ids using params not correct, params query string or post. need bit effort params path.

before_filter: get_resources # replace 2 filters  private def get_resources   book_id, chapter_id = request.path.split('/')[1, 3]   @book    = book.find(book_id)   @chapter = chapter.find(chapter_id) end 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -