简体   繁体   English

Rails的问题

[英]Rails belongs_to issues

I was trying to follow the answer provided by this post About Event_calendar.Showing only events for current user and not all events present 我正在尝试按照此帖子提供的答案关于Event_calendar。仅显示当前用户的事件,而不显示所有事件

However when I tried to add the belongs_to user in the event model, it gives me the following error. 但是,当我尝试在事件模型中添加belongs_to user时,出现以下错误。

NameError (undefined local variable or method 'user' for #<Class:0x007fff15d1f6c0>):
  app/models/event.rb:3:in '<class:Event>'
  app/models/event.rb:1:in '<top (required)>'
  app/controllers/calendar_controller.rb:9:in 'index'


  Rendered .../.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.8ms)
  Rendered .../.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
  Rendered .../.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (23.6ms)

in my user.rb model I have included has_many :events 在我的user.rb模型中,我包含了has_many :events

Any idea how to fix this? 任何想法如何解决这个问题?

belongs_to :user

您必须在前面加上:使其成为符号,否则将其解析为方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM