adam
May 19, 2008, 1:51pm
1
I’ve a problem in, my view where the object found via find method,
cant be seen
i get a
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.to_sym
Error every time i try to edit the record, the weird thing is that in
the debugger the object is created
I use restful routing for news
in routes.rb
map.resources :news, :singular=>:news_instance
In the view
<% form_for @news do |n| %>
<%= render :partial=>‘form’, :locals=>{:n=>n,:btn_name=>‘dodaj’}
%>
<% end %>
I gues this could be a bug (?)
Anyway to get around it?
adam
May 19, 2008, 5:52pm
2
Can you post the full trace dump?
adam
May 19, 2008, 5:53pm
3
Can you post the backtrace?
adam
May 19, 2008, 6:05pm
4
What he said! Great minds think alike!
adam
May 19, 2008, 9:00pm
5
here it goes:
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
activesupport-2.0.2/lib/active_support/core_ext/hash/keys.rb:27:in
symbolize_keys' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ activesupport-2.0.2/lib/active_support/core_ext/hash/keys.rb:26:ineach’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
activesupport-2.0.2/lib/active_support/core_ext/hash/keys.rb:26:in
inject' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ activesupport-2.0.2/lib/active_support/core_ext/hash/keys.rb:26:insymbolize_keys’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_view/helpers/url_helper.rb:69:in url_for' (eval):17:innews_path’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/polymorphic_routes.rb:27:in
polymorphic_url' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/polymorphic_routes.rb:31:inpolymorphic_path’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_view/helpers/form_helper.rb:200:in
apply_form_for_options!' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_view/helpers/form_helper.rb:179:inform_for’
app/views/news/edit.html.erb:4:in
_run_erb_47app47views47news47edit46html46erb' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_view/base.rb:637:incompile_and_render_template’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_view/base.rb:365:in render_template' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_view/base.rb:316:inrender_file’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/base.rb:1100:in
render_for_file' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:836:inrender’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/layout.rb:262:in
render_with_a_layout' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:inrender_with_benchmark’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/1.8/benchmark.rb:
293:in measure' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:inrender_with_benchmark’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/base.rb:1153:in
default_render' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:1159:inperform_action’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/filters.rb:697:in
call_filters' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/filters.rb:689:inperform_action_with_filters’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in
perform_action_with_benchmark' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/1.8/benchmark.rb: 293:inmeasure’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in
perform_action_with_benchmark' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/rescue.rb:199:inperform_action_with_rescue’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/caching.rb:678:in
perform_action_with_caching' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/connection_adapters/abstract/ query_cache.rb:33:incache’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
activerecord-2.0.2/lib/active_record/query_cache.rb:8:in cache' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/caching.rb:677:inperform_action_with_caching’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/base.rb:524:in process' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/filters.rb:685:inprocess_with_filters’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/session_management.rb:123:in
process_with_session_management_support' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:388:inprocess’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in
handle_request' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:indispatch’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in
dispatch_cgi' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:indispatch’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/
rails-2.0.2/lib/webrick_server.rb:112:in handle_dispatch' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/gems/1.8/gems/ rails-2.0.2/lib/webrick_server.rb:78:inservice’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/1.8/webrick/
httpserver.rb:104:in service' /usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/1.8/webrick/ httpserver.rb:65:inrun’
/usr/local/netbeans-6.1/ruby2/jruby-1.1/lib/ruby/1.8/webrick/server.rb:
173:in start_thread' :1:instart’
adam
May 19, 2008, 10:02pm
6
<%= render :partial=>‘menu’ %>
<%= error_messages_for :news %>
<%unless @news.nil ?%>
<% form_for @news do |n| %>
<%= render :partial=>‘form’, :locals=>{:n=>n,:btn_name=>‘add’} %>
<% end %>
<%end%>
the partial _menu
news
<%= '' + link_to('add',new_news_instance_path,
{:class=>:add}) + ' ' if session[:user_level]>1 %>
<%= link_to 'list',news_path,
{:class=>:list,:title=>"list"} %>
adam
May 19, 2008, 10:12pm
7
I am thinking that one of the items in the @news object is nil
You check to see if the object is nil, but not each item
<%unless @news.nil ?%>
<% form_for @news do |n| %>
#<%= render :partial=>‘form’, :locals=>{:n=>n,:btn_name=>‘add’}
%>
<%= (render :partial=>‘form’, :locals=>{:n=>n,:btn_name=>‘add’})
if n %>
<% end %>
<%end%>
Just my guess. Lets see what Andy finds.
adam
May 19, 2008, 10:38pm
8
I did that check after the errors started to pop out and i couldn’t
find the solution ;/
adam
May 19, 2008, 9:23pm
9
The backtrace shows that there’s a problem in line 4 but you’ve only
shown 3 lines from the template. My guess is that there is something
wonky in the partial that you’re including (which means there are two
lines before the render :partial). If you can show the partial and
the edit method we might get somewhere.
adam
May 19, 2008, 10:59pm
10
I am a little confused about how you are calling the partial. I think
Rails will interate through all the items in the @news array (if it is
an array) in the partial without you having to do so explicitly. I am
not at a spot where I can look it up right now.
adam
May 20, 2008, 11:00am
11
the controller for the edit action
def edit
@news = News.find(params[:id])
end
def update
@news = News.find(params[:id])
respond_to do |format|
if @news.update_attributes(params[:news])
format.html { redirect_to(@news) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @news.errors, :status
=> :unprocessable_entity }
end
end
end
adam
May 20, 2008, 1:43am
12
And yet, you still haven’t shown us the controller code!
Please do.
–
Appreciated my help?
Reccommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg
adam
May 20, 2008, 2:09pm
13
I have a feeling that the root of the problem is with the name of your
class.
“news”.puralize
#=> “news”
If I am correct, the code is having trouble with an ambiguous route on
line 8 of your partial:
<%= link_to ‘list’,news_path, {:class=>:list,:title=>“list”} %>
The framework is assuming that ‘news_path’ is the name of a singular
route (rather than the name of the collection/index) and it’s looking
for an instance of the News class upon which to call to_param so that
it can build a path along the lines of news_path(:news_id=>@news).
The ‘rails-magic’ that transforms the instance into a symbolized key
for the hash is unhappy.