# NoMethodError in partial driving me mad

**URL:** <https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839>\
**Category:** Rails\
**Created:** [July 19, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839 "2007-07-19T15:00:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 19, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/1 "2007-07-19T15:00:37Z")

</div>

Hello,

i simplified have a news model, a news category model and a news  
controller.  
my \_news.rhtml partial renders a single news entry.

in my controller there are the actions show and show\_category.  
if the “show” action is called, a single news item is rendered through  
my partial with no errors.

if the “show\_category” action is called, i get a NoMethodError while  
displaying my news through the partial.

## news\_controller.rb:

def show  
@news = News.find(params[:id])  
render\_partial ‘news’  
end

def show\_category  
@news = NewsCategory.find(params[:id]).news  
render\_partial ‘news’, :collection =\> @news  
end

## \_news.rhtml:

# \<%=h news.title %\> - Kategory: \<%= news.news\_category.title %\>

\<%= bbcodeize news.content %\>

erstellt von \<%=link\_to news.user.login, :controller =\> "user", :action =\> "show", :id =\> news.user.id %\> vor \<%= time\_ago\_in\_words news.created\_at %\>. \<%= "zuletzt geändert vor " + time\_ago\_in\_words(news.updated\_at) unless news.updated\_at.nil? %\>

## ERROR:

NoMethodError in News#show\_category

Showing app/views/news/\_news.rhtml where line #2 raised:

undefined method `title’ for News:Class

Extracted source (around line #2):

1:

  
2: 
# \<%=h news.title %\> - Kategory: \<%= news.news\_category.title %\>
  
3: 

4: \<%= bbcodeize news.content %\>  
5:

RAILS\_ROOT: script/…/config/…  
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
base.rb:1235:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ associations/has_many_association.rb:111:in`send’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
associations/has\_many\_association.rb:111:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:946:in`with\_scope’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
associations/has\_many\_association.rb:103:in `method_missing' #{RAILS_ROOT}/app/views/news/_news.rhtml:2:in`\_run\_rhtml\_47app47views47news47\_news46rhtml’  
app/controllers/news\_controller.rb:56:in `show_category' -e:4:in`load’  
-e:4

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
base.rb:1235:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ associations/has_many_association.rb:111:in`send’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
associations/has\_many\_association.rb:111:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:946:in`with\_scope’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
associations/has\_many\_association.rb:103:in `method_missing' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb: 326:in`send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:  
326:in `compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb: 301:in`render\_template’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:  
260:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb: 275:in`render’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/  
partials.rb:59:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ benchmarking.rb:26:in`benchmark’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/1.8/benchmark.rb:307:in`realtime’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:26:in `benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/ partials.rb:58:in`render\_partial’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:850:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:1095:in`send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:1095:in `perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:632:in`call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:634:in `call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:619:in`perform\_action\_without\_benchmark’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ rescue.rb:83:in`perform\_action’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:430:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:430:in`process\_without\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:624:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ session_management.rb:114:in`process’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:330:in `process' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in`dispatch’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in  
`process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in`synchronize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in`process\_client’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in`process\_client’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in`initialize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in  
`initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in`new’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb: 271:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:  
270:in `each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb: 270:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:127:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb: 211:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:243  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:488:in `load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:488:in`load’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:488:in`load’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/  
mongrel.rb:60  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:495:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:342:in`new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:495:in `require' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`gem\_original\_require’  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require’  
script/server:3

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
base.rb:1235:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ associations/has_many_association.rb:111:in`send’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
associations/has\_many\_association.rb:111:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:946:in`with\_scope’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
associations/has\_many\_association.rb:103:in `method_missing' #{RAILS_ROOT}/app/views/news/_news.rhtml:2:in`\_run\_rhtml\_47app47views47news47\_news46rhtml’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:  
326:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb: 326:in`compile\_and\_render\_template’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:  
301:in `render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb: 260:in`render\_file’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:  
275:in `render' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/ partials.rb:59:in`render\_partial’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:26:in `benchmark' /usr/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/usr/lib/ruby/1.8/benchmark.rb:307:in `realtime' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ benchmarking.rb:26:in`benchmark’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/  
partials.rb:58:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:850:in`render\_partial’  
app/controllers/news\_controller.rb:56:in `show_category' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:1095:in`send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:1095:in `perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:632:in`call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:634:in `call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:619:in`perform\_action\_without\_benchmark’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ rescue.rb:83:in`perform\_action’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:430:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:430:in`process\_without\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:624:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ session_management.rb:114:in`process’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:330:in `process' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in`dispatch’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in  
`process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in`synchronize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in`process\_client’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in`process\_client’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in`initialize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in  
`initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in`new’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb: 271:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:  
270:in `each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb: 270:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:127:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb: 211:in`run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:243  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:488:in `load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:488:in`load’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:488:in`load’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/  
mongrel.rb:60  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:495:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:342:in`new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:495:in `require' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`gem\_original\_require’  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' script/server:3 -e:4:in`load’  
-e:4

help please! ☹

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 19, 2007, 4:00pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/2 "2007-07-19T16:00:36Z")

</div>

> ## news\_controller.rb:
> 
> def show  
> @news = News.find(params[:id])  
> render\_partial ‘news’  
> end
> 
> def show\_category  
> @news = NewsCategory.find(params[:id]).news  
> render\_partial ‘news’, :collection =\> @news  
> end

> ## ERROR:
> 
> NoMethodError in News#show\_category
> 
> Showing app/views/news/\_news.rhtml where line #2 raised:
> 
> undefined method `title’ for News:Class
> 
> Extracted source (around line #2):
> 
> 1:
> 
>   
> 2: 
> # \<%=h news.title %\> - Kategory: \<%= news.news\_category.title
> 
> i belive this has to do with how rails is trying to convert  
> single-plural names … you’ve chosen a kind of ambiguas one, because  
> news and news are both plural and singular … so what rails thinks is
> 
> > ```
> > @news = News.find(params[:id])
> > render_partial 'news'
> > 
> > ```
> 
> # here the variable news=a new News object (one object only) - good
> 
> > ```
> > render_partial 'news', :collection => @news
> > 
> > ```
> 
> # and here the variable news=the collection (not one object) - not good
> 
> change the @news variable in the show\_category def to @newses or  
> something like similar … either way, that should be the problem
> 
> hth

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 19, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/3 "2007-07-19T16:15:57Z")

</div>

On 19 Jul., 16:00, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ```
> > render_partial 'news', :collection => @news
> > 
> > ```
> 
> # here the variable news=a new News object (one object only) - good
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

i tried this but it did not work.

here is the new show\_category action:

def show\_category  
@newses = NewsCategory.find(params[:id]).news  
render\_partial ‘news’, :collection =\> @newses  
end

the new error is:

NoMethodError in News#show\_category

Showing app/views/news/\_news.rhtml where line #2 raised:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.title

Extracted source (around line #2):

1:

  
2: 
# \<%=h news.title %\> - Kategory: \<%= news.news\_category.title %\>
  
3: 

4: \<%= bbcodeize news.content %\>  
5:

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 22, 2007, 1:49pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/4 "2007-07-22T13:49:13Z")

</div>

still no one hast a answer for this problem?  
im stuck till now… ☹

to sum up, first error was a noMethodError for  
News:Class

second one a nil object…

help! ☹

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 22, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/5 "2007-07-22T14:51:30Z")

</div>

have you tried testing the News class and the NewsCategory class  
associations? I see a has\_many association in the first full trace…  
Can you test if it the news\_category is working correctly?

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 22, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/6 "2007-07-22T15:18:26Z")

</div>

> def show\_category  
> @newses = NewsCategory.find(params[:id]).news  
> render\_partial ‘news’, :collection =\> @newses  
> end
> 
> the new error is:
> 
> NoMethodError in News#show\_category
> 
> Showing app/views/news/\_news.rhtml where line #2 raised:
> 
> You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.title

the error you got was a ‘nil’ error, because no variable was passed:

you need to change this line

> ```
> render_partial 'news', :collection => @newses
> 
> ```

to this line  
render :partial =\> ‘news’, :collection =\> @newses

…when you use render\_partial, you are not passing the collection; it’s  
a syntax thing. if you use render :partial =\> x , :collection =\> y it  
should pass the collection to the partials.

hth

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 22, 2007, 4:08pm UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/7 "2007-07-22T16:08:56Z")

</div>

Pascal,

You were almost there originally… you just need to pass the first  
call to render a locals hash so that the news variable in the partial  
is populated correctly. The collection render does it automatically.  
BTW, your problem does not appear to have anything to do with Rails  
pluralization.

def show  
@news = News.find(params[:id])  
render :partial =\> ‘news’, :locals =\> { :news =\> @news }  
end

def show\_category  
@news = NewsCategory.find(params[:id]).news  
render :partial =\> ‘news’, :collection =\> @news  
end

Cheers,  
Obie

On 7/19/07, Pascal F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> h1\>
> 
>   
> Extracted source (around line #2):
> 
> #{RAILS\_ROOT}/app/views/news/\_news.rhtml:2:in  
> associations/has\_many\_association.rb:111:in `method_missing' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb: benchmarking.rb:26:in `benchmark’  
> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
> `dispatch' `process\_client’  
> 271:in `run' dependencies.rb:488:in `load’  
> /usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' script/server:3 associations/has_many_association.rb:103:in `method\_missing’  
> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:  
> partials.rb:58:in `render_partial' filters.rb:634:in `call\_filter’  
> base.rb:430:in `send' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run’  
> /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:  
> /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
> /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
> -e:4:in `load’  
> -e:4
> 
> help please! ☹
> 
> >

–  
Obie F.

> **[Best Online Casino in Australia | Top Licensed Casinos for Gamblers](https://toponlinecasinoaustralia.com)**
>
> Best Online Casino in Australia with licensed games only. Play blackjack, roulette, poker and other top-notch casino games. Enjoy gambling 24/7.

Pre-order my book The Rails Way today!  
[http://www.amazon.com/dp/0321445619](http://www.amazon.com/dp/0321445619)

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 23, 2007, 10:57am UTC](https://www.ruby-forum.com/t/nomethoderror-in-partial-driving-me-mad/109839/8 "2007-07-23T10:57:48Z")

</div>

oh my god, this is it! it works.

did not realy understand what the News:Class came from but… its gone  
now  
and iam happy 🙂  
i’ll try to understand this later after finishing (finally) my tiny app.

tanks

Pascal
