# error in runtime controller#view

**URL:** <https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376>\
**Category:** rubyonrails-talk\
**Created:** [July 4, 2012, 4:23am UTC](https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376 "2012-07-04T04:23:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_Sharma](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@Abhishek\_Sharma](https://discuss.rubyonrails.org/u/Abhishek_Sharma)\
**Post date:** [July 4, 2012, 4:23am UTC](https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376/1 "2012-07-04T04:23:42Z")

</div>

```ruby
m getting an error "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id"

```

```ruby
when i'm creating new record,like a topic has many discussions,when i'm creating a new discussions m getting that error..i already assign the topic id as foreign key in discussions controller....please sort out this problem.if u getting the same..how you rectify those errors..and in how many cases this errors are prone to occur???

```

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [July 4, 2012, 4:38am UTC](https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376/2 "2012-07-04T04:38:30Z")

</div>

We need more information to help you , can you post part of the relevant code?

---

<div class="post-metadata">

**Author:** ![Abhishek\_Sharma](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@Abhishek\_Sharma](https://discuss.rubyonrails.org/u/Abhishek_Sharma)\
**Post date:** [July 4, 2012, 6:14am UTC](https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376/3 "2012-07-04T06:14:30Z")

</div>

subjects has many pages

subject controller code::

class SubjectController \< ApplicationController

```
def list

	@subjects = Subject.order("subjects.position ASC")

end

def show

	@subject = Subject.find(params[:id])

end

def new

	@subject = Subject.new(:visible => 'false')

	@subject_count = Subject.count + 1

end

def create

	@subject = Subject.new(params[:subject])

	if @subject.save

		redirect_to(:action => 'list')

	else

		render('new')

	end

end

```

end

page controller code::

class PageController \< ApplicationController

before\_filter :find\_subject

def index

list

render(‘list’)

end

def list

@pages = Page.where(:subject\_id =\> @[subject.id](http://subject.id))

end

def show

@page = Page.find(params[:id])

end

def new

@page = Page.new(:subject\_id =\> @[subject.id](http://subject.id))

@page\_count = @subject.pages.size + 1

@subjects = Subject.order(‘position ASC’)

end

def create

@page = Page.new(params[:page])

if @page.save

redirect\_to(:action =\> ‘list’, :subject\_id =\> @page.subject\_id)

else

render(‘new’)

end

end

private

def find\_subject

if params[:subject\_id]

@subject = Subject.find\_by\_id(params[:subject\_id])

end

end

end

this is my controller code and when m creating new page m getting dat error…

---

<div class="post-metadata">

**Author:** ![Michael\_Pavling](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@Michael\_Pavling](https://discuss.rubyonrails.org/u/Michael_Pavling)\
**Post date:** [July 4, 2012, 8:03am UTC](https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376/4 "2012-07-04T08:03:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [July 4, 2012, 8:05am UTC](https://discuss.rubyonrails.org/t/error-in-runtime-controller-view/64376/5 "2012-07-04T08:05:22Z")

</div>

This means that you have some code some\_object.id where some\_object is nil. The error message should tell you which line is failing. Have a look at the Rails Guide on debugging for ideas on how to debug your code to find the problem.

Colin
