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!

  1. your @user variable set user's id, not user model instance
  2. you try calendar @user, whilst calendar correct field name, defined @ models/user.rb
  3. you try calendar user id, not user

the solution is:

  1. replace line

    @user = current_user.id 

    with

    @user = current_user 
  2. replace line

    @calendar = @user.calendar.new 

    with

    @calendar = @user.calendar.new 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -