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!