2011-05-07 50 views
0

我遇到顯示嵌套控制器的值的問題。我可以更新該字段,我只是看不到顯示頁面上的值。我認爲這是Devise的一個問題。顯示來自嵌套窗體的值的問題

我的用戶模型如下:

class User < ActiveRecord::Base 
    has_one :page 
    accepts_nested_attributes_for :page, :allow_destroy => true 

devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :name 


    has_friendly_id :name, :use_slug => true, :strip_non_ascii => true 
    validates_presence_of :name 
    validates_uniqueness_of :name 
    validates_uniqueness_of :email, :case_sensitive => false 

#creates a new page on user create if one doesn't exist 
    def after_initialize 
     self.build_page if self.page.nil? 
    end 

    end 

我的頁面模式:

class Page < ActiveRecord::Base 
    belongs_to :user 
    attr_accessible :tagline, :about, :email, :phone, :website, :blog, :user,    
end 

的routes.rb

Ahoy::Application.routes.draw do 

    resources :users, :path => '/' do 
    resource :page 
    end 

    devise_for :users, :controllers => { :registrations => "registrations"} 

    get "home/index" 
    get "home/about" 

    root :to => "home#index" 

end 

在我的用戶#表明我有這樣的:

<p> 
    <strong>Tagline</strong> 
    <%= @user.tagline %> 
</p> 

我得到一個未定義的方法。也試過,@ pages.tagline等

我不覺得我需要修改我的控制器?你能幫我嗎?

回答

1

tagline方法在Page定義,所以它應該是@user.page.tagline

+0

謝謝你,非常有幫助。 – 2011-05-09 17:44:03