1

私はauthenticantonにdevise+omniaouthを使用しています。私のユーザーには、次の関係を持つプロファイルもあります。

class User < ActiveRecord::Base
 has_many :authentications
 has_one :profile
 accepts_nested_attributes_for :profile
 attr_accessible :email, :password, :password_confirmation, :remember_me, :profile_attributes
etc.

したがって、私のregistrations/new.html.erbは次のようになります。

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

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

<h2><%= f.label :email %></h2>
<p><%= f.text_field :email %></p>

<h2><%= f.label :password %></h2>
<p><%= f.password_field :password %></p>

<h2><%= f.label :password_confirmation %></h2>
<p><%= f.password_field :password_confirmation %></p>

<p><%= f.submit "Sign up" %></p>

<br/>
<%= render :partial => "devise/shared/links" %>
<% end %>

<%= render "links" %>

ご覧のとおり、プロファイルから入力しようとしている属性は「name」のみです。これは正しく機能し、/ users / sign_upからサインアップしようとすると、名前、電子メール、およびパスワードを入力する必要があります。

今、私はモーダルウィンドウからこの登録ウィンドウを表示しようとしているので、同じ情報で/views/devise/menu/_registration_items.html.erbを作成しました:

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

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

<h2><%= f.label :email %></h2>
<p><%= f.text_field :email %></p>

<h2><%= f.label :password %></h2>
<p><%= f.password_field :password %></p>

<h2><%= f.label :password_confirmation %></h2>
<p><%= f.password_field :password_confirmation %></p>

<p><%= f.submit "Sign up" %></p>

<br/>

<% end %>

また、これをアプリケーションコントローラーに追加しました(ヘルパーに配置した場合も同じように機能します)。

 def resource_name
   :user
 end

 def resource
   @resource ||= User.new
 end

 def devise_mapping
   @devise_mapping ||= Devise.mappings[:user]
 end

https://github.com/plataformatec/devise/wiki/How-To%3a-Display-a-custom-sign_in-form-anywhere-in-your-appで説明されているように

名前フィールドがフォームで表示されないことを除いて、すべてが正常に機能します(たとえば、そのフィールド名がないログインフォームは正しく機能します)。何か他のものをマッピングする必要があると思いますが、それが何であるかわかりません。

ありがとう!

4

1 に答える 1

1

を追加するのを忘れていました

<% resource.build_profile %>

フォームの上部にある行。

于 2013-02-05T00:43:06.377 に答える