我正在嘗試在用戶頁面上放置一個日曆。我添加了路線到routes.rb
文件。但我不明白爲什麼它不起作用。未定義的方法`Calendar'for 2:Fixnum
route.rb
resources :users do
resources :calendars
end
該錯誤被說成是在calendars_controler.rb的21
行:
19 def new
20 @user = current_user.id
21 @calendar = @user.Calendar.new
22 end
application.erb
<h1> <% picture3 = image_tag("../images/twit.png", :border =>0, :class =>"smallh1", :class => "blue")%> </h1>
<%= link_to picture3, new_user_calendar_path(current_user.id) %>
個
型號/ user.rb
has_one :calendar
attr_accessible :calendar_id
我加入了user_id
領域日曆指數頁。
型號/ calendar.rb
attr_accessible :event, :published_on, :description, :user_id
belongs_to :user, :foreign_key => :user_id
任何幫助,將不勝感激!