开发者

Problems Displaying Values from Nested Form

I'm having issues displaying values from a nested controller. I can update the field just fine, I just cannot see the values on the show page. I think it's an issue with Devise.

My user model is as follows:

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 => tr开发者_开发百科ue, :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

My pages model:

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

In my users#show I have this:

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

And I get a undefined method. Have also tried, @pages.tagline etc.

I didn't think I needed to amend my controller? Can you help?


The tagline method is defined in Page, so it should be @user.page.tagline

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜