2010-03-02 6 views
0

J'ai une erreur dans mon nifty_scaffold ... Pour une raison quelconque (n'a pas changé de code standard, vérifié les routes.rb, ...) , créer une nouvelle nutrition ne fonctionnera pas.NoMethodError dans Nutritions # new - méthode non définie '' pour nil: NilClass

Quelqu'un pourrait-il m'expliquer comment et quelle est la solution?

Je pense que je l'ai compris tout le code necessairy ...

L'erreur en détail est: méthode non définie generated_methods' pour nul: NilClass

Route contient:

map.resources :nutritions 

Voir : Nouveau

<% title "New Nutrition" %> 
<%= render :partial => 'form' %> 
<p><%= link_to "Back to List", nutritions_path %></p> 

Afficher: _form

<% form_for @nutrition do |f| %> 
    <%= f.error_messages %> 
    <p> 
    <%= f.label :name %><br /> 
    <%= f.text_field :name %> 
    </p> 
    <p> 
    <%= f.label :description %><br /> 
    <%= f.text_area :description %> 
    </p> 
    <p> 
    <%= f.label :ammount %><br /> 
    <%= f.text_field :ammount %> 
    </p> 
    <p> 
    <%= f.label :unit %><br /> 
    <%= f.text_field :unit %> 
    </p> 
    <p> 
    <%= f.label :kcal %><br /> 
    <%= f.text_field :kcal %> 
    </p> 
    <p> 
    <%= f.label :protein %><br /> 
    <%= f.text_field :protein %> 
    </p> 
    <p> 
    <%= f.label :carb %><br /> 
    <%= f.text_field :carb %> 
    </p> 
    <p> 
    <%= f.label :fat %><br /> 
    <%= f.text_field :fat %> 
    </p> 
    <p> 
    <%= f.label :type %><br /> 
    <%= f.text_field :type %> 
    </p> 
    <p> 
    <%= f.label :class %><br /> 
    <%= f.text_field :class %> 
    </p> 
    <p><%= f.submit "Submit" %></p> 
<% end %> 

Et mon contrôleur de nutrition

def new 
    @nutrition = Nutrition.new 
    #raise @progress.inspect (debug porpose, didn't help) 
    end 

Et c'est la trace complète

C: /ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib /active_support/whiny_nil.rb:52:in method_missing' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:352:in respond_to? ' C: /ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/array/wrapper.rb: 14: dans wrap' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/helpers/active_record_helper.rb:174:in error_messages_for 'C:/ruby ​​/ lib/ruby ​​/ gems/1.8/gems/actionpack-2.3.5/lib/action_view/helpers/form_helper.rb: 1012: dans error_messages' D:/Workspace/Aptana/UltimateJournal/app/views/nutritions/_form.html.erb:3:in _run_erb_app47views47nutritions47_form46html46erb_locals_form_object 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view /helpers/form_helper.rb:499:in fields_for' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/helpers/form_helper.rb:282:in form_for 'D: /Workspace/Aptana/UltimateJournal/app/views/nutritions/_form.html.erb: 2: dans _run_erb_app47views47nutritions47_form46html46erb_locals_form_object' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:in envoyez' C:/ruby ​​/ lib/ruby ​​/ gems /1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:in render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:306:in with_template 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/ renderable.rb: 30: dans render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable_partial.rb:20:in render 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb: 26: dans benchmark' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in ms' C:/ruby ​​/ lib/ruby ​​/ gems/1.8/gems/actifsup port-2.3.5/lib/support_active/core_ext/benchmark.rb: 10: dans realtime' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in ms 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb : 26: dans benchmark' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable_partial.rb:19:in render 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/template.rb: 205: dans render_template' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable_partial.rb:44:in render_partial' C:/ruby ​​/ lib/ruby /gems/1.8/gems/actionpack-2.3.5/lib/action_view/partials.rb:184:in render_partial' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:267:in render 'D: /Workspace/Aptana/UltimateJournal/app/views/nutritions/new.html.erb dans _run_erb_app47views47nutritions47new46html46erb' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:in envoyez 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb: 34: dans render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:306:in with_template' C:/ruby ​​/ lib/ruby ​​/ gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb: 30: dans render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/template.rb:205:in render_template 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base .rb: 265: dans render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:348:in _render_with_layout 'C: /ruby/lib/ruby/gems/1.8/gems/actio npack-2.3.5/lib/action_view/base.rb: 262: dans render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1250:in render_for_file 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb: 945 : dans render_without_benchmark' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:51:in render 'C: /ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb: 17: dans ms' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:10:in realtime' C:/ruby ​​/ lib/ruby /gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in ms' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:51:in render 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/ lib/action_controller/base.rb: 1326: dans default_render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1332:in perform_action_without_filters 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb: 617: dans call_filters' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in perform_action_without_benchmark 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb: 68: dans perform_action_without_rescue' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in ms' C:/ruby ​​/ lib/ruby/gems/1.8/gems/activeupport-2.3.5/lib/support_active/core_ext/benchmark.rb: 10: dans realtime' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in ms 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5 /lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in perform_action_without_flash 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb: 146: dans perform_action' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in envoyer' C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb: 532: dans process_without_filters' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in processus 'C: /ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb: 391: dans process' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in appelez 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb : 437: dans call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in dispatch 'C:/ruby ​​/ lib/ruby ​​/ gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb: 121: dans _call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in build_middleware_stack 'C: /ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record /query_cache.rb:29:in call' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in appel 'C: /ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb: 34: dans cache' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in cache' C: /ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb: 28: dans call' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in appel 'C: /ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/string_coercion.rb: 25: dans call' C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in appelez 'C: /ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb: 24 : dans call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in appel 'C: /ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb: 93: dans call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in appel' C:/ruby ​​/ lib/ruby /gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in call' C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in sy nchronize 'C: /ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb: 11: dans call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in appel' C: /ruby/lib/ruby/gems/1.8/ gems/actionpack-2.3.5/lib/action_controller/reloader.rb: 34: dans run' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in appelez 'C: /ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/static .rb: 31: dans call' C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in appel 'C: /ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb: 40: dans each' C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in appel' C:/ruby ​​/ lib /ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/log_tailer.rb:17:in call' C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in appelez 'C: /ruby/lib/ruby/gems/1.8/gems/rack-1.0. 1/lib/rack/chunked.rb: 15: dans call' C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:64:in processus 'C: /ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb: 159 : dans process_client' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in chaque 'C: /ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb: 158: dans process_client' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in run' C:/ruby ​​/ lib /ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in initialize' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in new 'C: /ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb: 285: dans run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in initialize' C:/ruby ​​/ lib/ruby /gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in new' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in exécutez 'C: /ruby/lib/ruby/gems/1.8/gems/rack-1.0. 1/lib/crémaillère/handler/mongrel.rb: 34: dans run' C:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require » C: /ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31: require' script/server:3-e:2:in dans load'-e: 2

+0

Quelle est la pile d'erreur complète? (y compris le numéro de fichiers et de lignes de l'échec). –

Répondre

2

cela semble bien, juste nommer un attribut comme "classe" ne semble pas être une bonne idée, c'est généralement mot assez réservé ...

+0

Vous avez raison, j'ai ajouté des migrations au modèle (class, type => nutri_class, nutri_type). Ai-je besoin de changer quoi que ce soit d'autre dans mon nifty_scaffold? par exemple. Changer la vue, le contrôleur, ...? Parce que, mon nutri_class, nutri_type dans la vue de: action => "nouveau", avoir automatiquement le texte "Nutrition" en eux. Comment venir? – NicoJuicy

+0

vous devez changer les noms des champs dans vos vues, qui ont été générés par échafaudage, les valeurs par défaut seraient probablement définies dans la vue – deric

Questions connexes