我有这个模型
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
我想添加一个与此模型的关系
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
但是当我在表单中使用它时,它表示未定义的方法'年' 我试过belongs_to:users,has_many:user_detail已经相同了 这是在视图中
=f.text_field :year , placeholder: "Year"
记录错误
Started GET "/admin/users/new" for 127.0.0.1 at 2014-12-16 20:15:32 +0800
由Admin :: UsersController处理#new为HTML 呈现admin / app / views / admin / users / _form.html.haml(4.8ms) 在layouts / admin / application(6.7ms)中呈现admin / app / views / admin / users / new.html.haml 在11毫秒内完成500内部服务器错误
ActionView :: Template :: Error(未定义的方法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:in
值&#39;
actionview(4.1.7)lib / action_view / helpers / tags / base.rb:37:在value_before_type_cast'
actionview (4.1.7) lib/action_view/helpers/tags/text_field.rb:9:in
块中渲染&#39;
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:in
render&#39;
actionview(4.1.7)lib / action_view / helpers / form_helper.rb:771:在text_field'
actionview (4.1.7) lib/action_view/helpers/form_helper.rb:1258:in
text_field&#39;
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:in
来电&#39;
haml(4.1.0.beta.1)lib / haml / helpers / action_view_mods.rb:132:在block (2 levels) in form_for_with_haml'
haml (4.1.0.beta.1) lib/haml/helpers.rb:284:in
with_tabs&#39;
haml(4.1.0.beta.1)lib / haml / helpers / action_view_mods.rb:132:在block in form_for_with_haml'
actionview (4.1.7) lib/action_view/helpers/capture_helper.rb:38:in
块中捕获&#39;
actionview(4.1.7)lib / action_view / helpers / capture_helper.rb:200:在with_output_buffer'
haml (4.1.0.beta.1) lib/haml/helpers/action_view_xss_mods.rb:5:in
with_output_buffer_with_haml_xss&#39;
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:in
capture_with_haml&#39;
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:in
form_for_with_haml&#39;
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&#39;
actionview(4.1.7)lib / action_view / template.rb:145:在block in render'
activesupport (4.1.7) lib/active_support/notifications.rb:161:in
工具&#39;
actionview(4.1.7)lib / action_view / template.rb:339:在instrument'
actionview (4.1.7) lib/action_view/template.rb:143:in
渲染&#39;
actionview(4.1.7)lib / action_view / renderer / partial_renderer.rb:306:在render_partial'
actionview (4.1.7) lib/action_view/renderer/partial_renderer.rb:279:in
块中渲染&#39;
actionview(4.1.7)lib / action_view / renderer / abstract_renderer.rb:38:在block in instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in
块中的仪器&#39;
activesupport(4.1.7)lib / active_support / notifications / instrumenter.rb:20:in instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in
instrument&#39;
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:in
render&#39;
actionview(4.1.7)lib / action_view / renderer / renderer.rb:47:在render_partial'
actionview (4.1.7) lib/action_view/renderer/renderer.rb:21:in
渲染&#39;
actionview(4.1.7)lib / action_view / helpers / rendering_helper.rb:32:在render'
haml (4.1.0.beta.1) lib/haml/helpers/action_view_mods.rb:10:in
块中的render_with_haml&#39;
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:in
render_with_haml&#39;
admin / app / views / admin / users / new.html.haml:1:在_admin_app_views_admin_users_new_html_haml___282327175__623578238'
actionview (4.1.7) lib/action_view/template.rb:145:in
块中渲染&#39;
activesupport(4.1.7)lib / active_support / notifications.rb:161:in instrument'
actionview (4.1.7) lib/action_view/template.rb:339:in
instrument&#39;
actionview(4.1.7)lib / action_view / template.rb:143:在render'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:55:in
块(2级)中的render_template&#39;
actionview(4.1.7)lib / action_view / renderer / abstract_renderer.rb:38:在block in instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in
块中的仪器&#39;
activesupport(4.1.7)lib / active_support / notifications / instrumenter.rb:20:in instrument'
activesupport (4.1.7) lib/active_support/notifications.rb:159:in
instrument&#39;
actionview(4.1.7)lib / action_view / renderer / abstract_renderer.rb:38:在render_template中的instrument'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:54:in
块中&#39;
actionview(4.1.7)lib / action_view / renderer / template_renderer.rb:62:在render_with_layout'
actionview (4.1.7) lib/action_view/renderer/template_renderer.rb:53:in
render_template&#39;
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:in
render_template&#39;
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&#39;
actionpack(4.1.7)lib / action_controller / metal / streaming.rb:217:在_render_template'
actionview (4.1.7) lib/action_view/rendering.rb:82:in
render_to_body&#39;
actionpack(4.1.7)lib / action_controller / metal / rendering.rb:32:在render_to_body'
actionpack (4.1.7) lib/action_controller/metal/renderers.rb:32:in
render_to_body&#39;
actionpack(4.1.7)lib / abstract_controller / rendering.rb:25:in render'
actionpack (4.1.7) lib/action_controller/metal/rendering.rb:16:in
render&#39;
actionpack(4.1.7)lib / action_controller / metal / instrumentation.rb:41:在block (2 levels) in render'
activesupport (4.1.7) lib/active_support/core_ext/benchmark.rb:12:in
块中的ms&#39;
/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:in
ms&#39;
actionpack(4.1.7)lib / action_controller / metal / instrumentation.rb:41:在block in render'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:84:in
cleanup_view_runtime&#39;
actionpack(4.1.7)lib / action_controller / metal / instrumentation.rb:40:在render'
actionpack (4.1.7) lib/action_controller/metal/implicit_render.rb:10:in
default_render&#39;
actionpack(4.1.7)lib / action_controller / metal / implicit_render.rb:5:在send_action'
actionpack (4.1.7) lib/abstract_controller/base.rb:189:in
process_action&#39;
actionpack(4.1.7)lib / action_controller / metal / rendering.rb:10:在process_action&#39;中的process_action'
actionpack (4.1.7) lib/abstract_controller/callbacks.rb:20:in
块中
activesupport(4.1.7)lib / active_support / callbacks.rb:82:in run_callbacks'
actionpack (4.1.7) lib/abstract_controller/callbacks.rb:19:in
process_action&#39;
actionpack(4.1.7)lib / action_controller / metal / rescue.rb:29:在process_action&#39;中的process_action'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:31:in
块中
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:in
instrument&#39;
activesupport(4.1.7)lib / active_support / notifications.rb:159:在instrument'
actionpack (4.1.7) lib/action_controller/metal/instrumentation.rb:30:in
process_action&#39;
actionpack(4.1.7)lib / action_controller / metal / params_wrapper.rb:250:process_action'
actionpack (4.1.7) lib/abstract_controller/base.rb:136:in
进程&#39;
actionview(4.1.7)lib / action_view / rendering.rb:30:在process'
actionpack (4.1.7) lib/action_controller/metal.rb:196:in
发送&#39;
actionpack(4.1.7)lib / action_controller / metal / rack_delegation.rb:13:在dispatch'
actionpack (4.1.7) lib/action_controller/metal.rb:232:in
阻止行动&#39;
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:in
dispatch&#39;
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:in
阻止来电&#39;
actionpack(4.1.7)lib / action_dispatch / journey / router.rb:59:在each'
actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:in
电话&#39;
actionpack(4.1.7)lib / action_dispatch / routing / route_set.rb:678:在call'
railties (4.1.7) lib/rails/engine.rb:514:in
电话&#39;
railties(4.1.7)lib / rails / railtie.rb:194:public_send'
railties (4.1.7) lib/rails/railtie.rb:194:in
method_missing&#39;
actionpack(4.1.7)lib / action_dispatch / journey / router.rb:73:block in call'
actionpack (4.1.7) lib/action_dispatch/journey/router.rb:59:in
每个&#39;
actionpack(4.1.7)lib / action_dispatch / journey / router.rb:59:在call'
actionpack (4.1.7) lib/action_dispatch/routing/route_set.rb:678:in
电话&#39;
rack(1.5.2)lib / rack / etag.rb:23:in call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in
call&#39;
rack(1.5.2)lib / rack / head.rb:11:in call'
actionpack (4.1.7) lib/action_dispatch/middleware/params_parser.rb:27:in
call&#39;
actionpack(4.1.7)lib / action_dispatch / middleware / flash.rb:254:在call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in
上下文&#39;
rack(1.5.2)lib / rack / session / abstract / id.rb:220:in call'
actionpack (4.1.7) lib/action_dispatch/middleware/cookies.rb:560:in
call&#39;
actionpack(4.1.7)lib / action_dispatch / middleware / callbacks.rb:29:在block in call'
activesupport (4.1.7) lib/active_support/callbacks.rb:82:in
run_callbacks&#39;
actionpack(4.1.7)lib / action_dispatch / middleware / callbacks.rb:27:in call'
actionpack (4.1.7) lib/action_dispatch/middleware/reloader.rb:73:in
call&#39;
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:in
call&#39;
actionpack(4.1.7)lib / action_dispatch / middleware / show_exceptions.rb:30:in call'
railties (4.1.7) lib/rails/rack/logger.rb:38:in
call_app&#39;
railties(4.1.7)lib / rails / rack / logger.rb:20:block in call'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in
块中标记的&#39;
activesupport(4.1.7)lib / active_support / tagged_logging.rb:26:in tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in
已标记&#39;
railties(4.1.7)lib / rails / rack / logger.rb:20:in call'
actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:in
来电&#39;
rack(1.5.2)lib / rack / methodoverride.rb:21:in call'
rack (1.5.2) lib/rack/runtime.rb:17:in
call&#39;
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:in
call&#39;
actionpack(4.1.7)lib / action_dispatch / middleware / static.rb:84:in call'
rack (1.5.2) lib/rack/sendfile.rb:112:in
call&#39;
railties(4.1.7)lib / rails / engine.rb:514:call'
railties (4.1.7) lib/rails/application.rb:144:in
电话&#39;
rack(1.5.2)lib / rack / lock.rb:17:in call'
rack (1.5.2) lib/rack/content_length.rb:14:in
call&#39;
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:in
service&#39;
/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:in
阻止在start_thread&#39;
呈现/home/laziendo/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb(1.8ms) 呈现/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) 在救援/布局(17.8ms)内呈现/home/laziendo/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb
答案 0 :(得分:0)
错误是说User没有名为'year'的方法,但它没有。 UserDetails的确如此。所以你需要从UserDetails访问年份。