0
votes

I have this model

  class User

  include Mongoid::Document
  authenticates_with_sorcery!
  has_one :user_details 

  field :email , type: String
  field :id_number , type: String
  field :crypted_password , type: String
  field :salt , type: String
  field :fname , type: String
  field :lname , type: String
  field :mname , type: String
end

And I want to add a relation to this model

class UserDetails
  include Mongoid::Document

  belongs_to :user

  #fields
  field :year , type: String
  field :block , type: String
  field :course , type: String
  field :alumni , type: Boolean
end

but when I used it in my form it says Undefined Method 'year' I tried to belongs_to :users, has_many :user_detail already still the same this is in the view

 =f.text_field :year , placeholder: "Year"

Log Error

Started GET "/admin/users/new" for 127.0.0.1 at 2014-12-16 20:15:32 +0800

Processing by Admin::UsersController#new as HTML Rendered admin/app/views/admin/users/_form.html.haml (4.8ms) Rendered admin/app/views/admin/users/new.html.haml within layouts/admin/application (6.7ms) Completed 500 Internal Server Error in 11ms

ActionView::Template::Error (undefined method term' for #<User:0xa9f0a24>): 66: %section.col.col-3 67: %label.input 68: %i.icon-prepend.fa.fa-user 69: =f.text_field :term , placeholder: "Year" 70: %b.tooltip.tooltip-top-left 71: %i.fa.fa-warning.text-warning-teal Year 72: %section.col.col-3 actionview (4.1.7) lib/action_view/helpers/tags/base.rb:28:invalue' actionview (4.1.7) lib/action_view/helpers/tags/base.rb:37:in value_before_type_cast' actionview (4.1.7) lib/action_view/helpers/tags/text_field.rb:9:inblock in render' actionview (4.1.7) lib/action_view/helpers/tags/text_field.rb:9:in fetch' actionview (4.1.7) lib/action_view/helpers/tags/text_field.rb:9:inrender' actionview (4.1.7) lib/action_view/helpers/form_helper.rb:771:in text_field' actionview (4.1.7) lib/action_view/helpers/form_helper.rb:1258:intext_field' admin/app/views/admin/users/_form.html.haml:69:in block in _admin_app_views_admin_users__form_html_haml___623088800__625367368' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:132:incall' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:132:in block (2 levels) in form_for_with_haml' haml (4.1.0.beta.1) lib/haml/helpers.rb:284:inwith_tabs' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:132:in block in form_for_with_haml' actionview (4.1.7) lib/action_view/helpers/capture_helper.rb:38:inblock in capture' actionview (4.1.7) lib/action_view/helpers/capture_helper.rb:200:in with_output_buffer' haml (4.1.0.beta.1) lib/haml/helpers/action_view_xss_mods.rb:5:inwith_output_buffer_with_haml_xss' actionview (4.1.7) lib/action_view/helpers/capture_helper.rb:38:in capture' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:47:incapture_with_haml' actionview (4.1.7) lib/action_view/helpers/form_helper.rb:434:in form_for' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:134:inform_for_with_haml' haml (4.1.0.beta.1) lib/haml/helpers/action_view_xss_mods.rb:28:in form_for_with_haml_xss' admin/app/views/admin/users/_form.html.haml:1:in_admin_app_views_admin_users__form_html_haml___623088800__625367368' actionview (4.1.7) lib/action_view/template.rb:145:in block in render' activesupport (4.1.7) lib/active_support/notifications.rb:161:ininstrument' actionview (4.1.7) lib/action_view/template.rb:339:in instrument' actionview (4.1.7) lib/action_view/template.rb:143:inrender' actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:306:in render_partial' actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:279:inblock in render' actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' activesupport (4.1.7) lib/active_support/notifications.rb:159:inblock in instrument' activesupport (4.1.7) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.1.7) lib/active_support/notifications.rb:159:ininstrument' actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in instrument' actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:278:inrender' actionview (4.1.7) lib/action_view/renderer/renderer.rb:47:in render_partial' actionview (4.1.7) lib/action_view/renderer/renderer.rb:21:inrender' actionview (4.1.7) lib/action_view/helpers/rendering_helper.rb:32:in render' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:10:inblock in render_with_haml' haml (4.1.0.beta.1) lib/haml/helpers.rb:89:in non_haml' haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:10:inrender_with_haml' admin/app/views/admin/users/new.html.haml:1:in _admin_app_views_admin_users_new_html_haml___282327175__623578238' actionview (4.1.7) lib/action_view/template.rb:145:inblock in render' activesupport (4.1.7) lib/active_support/notifications.rb:161:in instrument' actionview (4.1.7) lib/action_view/template.rb:339:ininstrument' actionview (4.1.7) lib/action_view/template.rb:143:in render' actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:55:inblock (2 levels) in render_template' actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' activesupport (4.1.7) lib/active_support/notifications.rb:159:inblock in instrument' activesupport (4.1.7) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.1.7) lib/active_support/notifications.rb:159:ininstrument' actionview (4.1.7) lib/action_view/renderer/abstract_renderer.rb:38:in instrument' actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:54:inblock in render_template' actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:62:in render_with_layout' actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:53:inrender_template' actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:17:in render' actionview (4.1.7) lib/action_view/renderer/renderer.rb:42:inrender_template' actionview (4.1.7) lib/action_view/renderer/renderer.rb:23:in render' actionview (4.1.7) lib/action_view/rendering.rb:99:in_render_template' actionpack (4.1.7) lib/action_controller/metal/streaming.rb:217:in _render_template' actionview (4.1.7) lib/action_view/rendering.rb:82:inrender_to_body' actionpack (4.1.7) lib/action_controller/metal/rendering.rb:32:in render_to_body' actionpack (4.1.7) lib/action_controller/metal/renderers.rb:32:inrender_to_body' actionpack (4.1.7) lib/abstract_controller/rendering.rb:25:in render' actionpack (4.1.7) lib/action_controller/metal/rendering.rb:16:inrender' actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:41:in block (2 levels) in render' activesupport (4.1.7) lib/active_support/core_ext/benchmark.rb:12:inblock in ms' /home/laziendo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in realtime' activesupport (4.1.7) lib/active_support/core_ext/benchmark.rb:12:inms' actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:41:in block in render' actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:84:incleanup_view_runtime' actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:40:in render' actionpack (4.1.7) lib/action_controller/metal/implicit_render.rb:10:indefault_render' actionpack (4.1.7) lib/action_controller/metal/implicit_render.rb:5:in send_action' actionpack (4.1.7) lib/abstract_controller/base.rb:189:inprocess_action' actionpack (4.1.7) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (4.1.7) lib/abstract_controller/callbacks.rb:20:inblock in process_action' activesupport (4.1.7) lib/active_support/callbacks.rb:82:in run_callbacks' actionpack (4.1.7) lib/abstract_controller/callbacks.rb:19:inprocess_action' actionpack (4.1.7) lib/action_controller/metal/rescue.rb:29:in process_action' actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:31:inblock in process_action' activesupport (4.1.7) lib/active_support/notifications.rb:159:in block in instrument' activesupport (4.1.7) lib/active_support/notifications/instrumenter.rb:20:ininstrument' activesupport (4.1.7) lib/active_support/notifications.rb:159:in instrument' actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:30:inprocess_action' actionpack (4.1.7) lib/action_controller/metal/params_wrapper.rb:250:in process_action' actionpack (4.1.7) lib/abstract_controller/base.rb:136:inprocess' actionview (4.1.7) lib/action_view/rendering.rb:30:in process' actionpack (4.1.7) lib/action_controller/metal.rb:196:indispatch' actionpack (4.1.7) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.1.7) lib/action_controller/metal.rb:232:inblock in action' actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:82:in call' actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:82:indispatch' actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:50:in call' actionpack (4.1.7) lib/action_dispatch/journey/router.rb:73:inblock in call' actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:in each' actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:incall' actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:678:in call' railties (4.1.7) lib/rails/engine.rb:514:incall' railties (4.1.7) lib/rails/railtie.rb:194:in public_send' railties (4.1.7) lib/rails/railtie.rb:194:inmethod_missing' actionpack (4.1.7) lib/action_dispatch/journey/router.rb:73:in block in call' actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:ineach' actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:in call' actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:678:incall' rack (1.5.2) lib/rack/etag.rb:23:in call' rack (1.5.2) lib/rack/conditionalget.rb:25:incall' rack (1.5.2) lib/rack/head.rb:11:in call' actionpack (4.1.7) lib/action_dispatch/middleware/params_parser.rb:27:incall' actionpack (4.1.7) lib/action_dispatch/middleware/flash.rb:254:in call' rack (1.5.2) lib/rack/session/abstract/id.rb:225:incontext' rack (1.5.2) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.1.7) lib/action_dispatch/middleware/cookies.rb:560:incall' actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:29:in block in call' activesupport (4.1.7) lib/active_support/callbacks.rb:82:inrun_callbacks' actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (4.1.7) lib/action_dispatch/middleware/reloader.rb:73:incall' actionpack (4.1.7) lib/action_dispatch/middleware/remote_ip.rb:76:in call' actionpack (4.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall' actionpack (4.1.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.1.7) lib/rails/rack/logger.rb:38:incall_app' railties (4.1.7) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:inblock in tagged' activesupport (4.1.7) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:intagged' railties (4.1.7) lib/rails/rack/logger.rb:20:in call' actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:incall' rack (1.5.2) lib/rack/methodoverride.rb:21:in call' rack (1.5.2) lib/rack/runtime.rb:17:incall' activesupport (4.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in call' rack (1.5.2) lib/rack/lock.rb:17:incall' actionpack (4.1.7) lib/action_dispatch/middleware/static.rb:84:in call' rack (1.5.2) lib/rack/sendfile.rb:112:incall' railties (4.1.7) lib/rails/engine.rb:514:in call' railties (4.1.7) lib/rails/application.rb:144:incall' rack (1.5.2) lib/rack/lock.rb:17:in call' rack (1.5.2) lib/rack/content_length.rb:14:incall' rack (1.5.2) lib/rack/handler/webrick.rb:60:in service' /home/laziendo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:inservice' /home/laziendo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in run' /home/laziendo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:inblock in start_thread'

Rendered /home/laziendo/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.8ms) Rendered /home/laziendo/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.7ms) Rendered /home/laziendo/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (17.8ms)

1
I guess year is a "Defined Variable", So change the parameter name and try!!!RubyOnRails
Still the same. I run rails console and run User.new but there's no such year,block,course,alumni fieldsnsantiago2719
Did you changed parameter name "year"...!RubyOnRails
yes I change it to field :term , type: Stringnsantiago2719
Can you show me your log error?RubyOnRails

1 Answers

0
votes

The error is saying that User doesn't have a method named 'year', which it doesn't. UserDetails does. So you need to access year from UserDetails.