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: --------------------------------- <div> <h1><%=h news.title %> - Kategory: <%= news.news_category.title %></ h1> <p> <%= bbcodeize news.content %> </p> <p> <span class="author"> 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? %></span> </p> </div> 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: <div> 2: <h1><%=h news.title %> - Kategory: <%= news.news_category.title %></h1> 3: <p> 4: <%= bbcodeize news.content %> 5: </p> 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! :( --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > 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: <div> > 2: <h1><%=h news.title %> - Kategory: <%= news.news_category.titlei 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Jul., 16:00, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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: <div> > > 2: <h1><%=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 > > -- > 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: <div> 2: <h1><%=h news.title %> - Kategory: <%= news.news_category.title %></h1> 3: <p> 4: <%= bbcodeize news.content %> 5: </p> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! :( --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? On Jul 22, 7:48 pm, Pascal Friederich <pau...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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! :(--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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.titlethe error you got was a ''nil'' error, because no variable was passed: you need to change this line> render_partial ''news'', :collection => @newsesto 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Friederich <paukul-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 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: > --------------------------------- > <div> > <h1><%=h news.title %> - Kategory: <%= news.news_category.title %></ > h1> > <p> > <%= bbcodeize news.content %> > </p> > <p> > <span class="author"> > 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? %></span> > </p> > </div> > > 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: <div> > 2: <h1><%=h news.title %> - Kategory: <%= news.news_category.title > %></h1> > 3: <p> > 4: <%= bbcodeize news.content %> > 5: </p> > > 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! :( > > > > >-- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 7/22/07, Shai Rosenfeld <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > 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 > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---