ruby on rails - undefined method `Calendar' for 2:Fixnum -
i trying put calendar on user page. added route routes.rb file. can not understand why doesn't work.
route.rb
resources :users resources :calendars end the error said @ line 21 of calendars_controler.rb:
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) %> models/user.rb
has_one :calendar attr_accessible :calendar_id i added user_id field calendar index page.
models/calendar.rb
attr_accessible :event, :published_on, :description, :user_id belongs_to :user, :foreign_key => :user_id any appreciated!
- your
@uservariable set user's id, not user model instance - you try
calendar@user, whilstcalendarcorrect field name, defined @ models/user.rb - you try
calendaruser id, not user
the solution is:
replace line
@user = current_user.idwith
@user = current_userreplace line
@calendar = @user.calendar.newwith
@calendar = @user.calendar.new
Comments
Post a Comment