On 4 July 2012 07:14, Abhishek Sharma <
ashar...@gmail.com> wrote:
> class PageController < ApplicationController
>
> before_filter :find_subject
>
> def new
> @page = Page.new(:subject_id => @
subject.id)
> @page_count = @subject.pages.size + 1
> @subjects = Subject.order('position ASC')
> end
>
> private
> def find_subject
> if params[:subject_id]
> @subject = Subject.find_by_id(params[:subject_id])
> end
> end
>
> end
You're calling find_subject on a before_filter, and it may or may not
populate a @subject object depending on whether there's a param value.
But your action then goes on to expect there to definitely be an
@subject instance variable. Put a breakpoint in find_subject, and see
what the parameter values are.