2012-02-02 18 views
2

こんにちは私は、追加フィールド、名前を追加してサインアップページをカスタマイズしようとしています。rails devise:ユーザーとアカウントのモデル

これは、私のアプリにプロファイルモデルを追加することによって行われます。しかし、私はまだ他のすべて動作するかどうかわからないけど、登録ページ

<h2>Sign up</h2> 

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 
    <%= devise_error_messages! %> 

    <div><%= f.label :email %><br /> 
    <%= f.email_field :email %></div> 

    <div><%= f.label :password %><br /> 
    <%= f.password_field :password %></div> 

    <div><%= f.label :password_confirmation %><br /> 
    <%= f.password_field :password_confirmation %></div> 

    <div><% f.fields_for :profile do |builder| %> 
    <p><%= builder.label :name %></p> 
    <p><%= builder.text_field :name %></p> 
    <% end %></div> 

    <div><%= f.submit "Sign up" %></div> 
<% end %> 

<%= render "links" %> 

# app/controllers/registrations_controller.rb 
class RegistrationsController < Devise::RegistrationsController 
    def new 
    super 
    profile = @user.build_profile 

    end 

    def create 
    super 

    end 

    def update 
    super 
    end 
end 

そして、私の新しいサインアップページ:

class Profile < ActiveRecord::Base 
     belongs_to :user 
    end 

    class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

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

    has_one :profile, :dependent => :destroy 

    accepts_nested_attributes_for :profile 
end 

私は、登録モデルをオーバーライド同じように見える。つまり、名前入力フィールドは表示されません。これをどうやって解決するのですか?

私には何が欠けていますか?

+0

1.makeを:ビューを変更するに

rails generate devise:views 

詳しい情報は工夫のwikiの "設定ビュー" で見つけることができます存在する場合は、 'f.fields_for'の前に' <%= f.object.profile.inspect%> 'のようなコードを記述することができます。2.新しいsign_upテンプレートが使用されているかどうかをチェックし、あなたはこれを持っている'config.scoped_views = true'はイニシャライザのdevise.rbディレクトリにあります。 –

+0

はプロファイルですが、その属性はnil ...ですが、それは問題ですか? – SuperString

+0

'attr_accessible:email、:password、:password_confirmation、:remember_me、:profile_attributes'を' attr_accessible:email、:password、:password_confirmation、:remember_me、:profile_attributes、:profile'に変更しよう –

答えて

0

あなたはビューを生成していないと思われます。あなたは以下を実行しましたか?必ず自分のプロフィールインスタンスがあり、

https://github.com/plataformatec/devise 

おかげ

Tabrez

関連する問題