ユーザープロファイルの編集ページでは、「clipclick gemを使用してアップロードされたすべての文書を取り込んで更新する必要がある」というカスタムフィールドを追加します。複数の文書をアップロードできます。Deviseユーザーの更新操作を無効にする
<div class="row">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}, multipart: true) do |f| %>
<div class="form-group">
<%= f.text_field :fullname, autofocus: true, placeholder: "Full Name *", class: "form-control" %>
</div>
<div class="form-group">
<%= f.email_field :email, placeholder: "Email *", class: "form-control" %>
</div>
<span class="btn btn-default btn-file btn-green pad_small">Upload Verification Documents
<input type="file" accept="application/pdf" name="input-file-preview"/>
<%= file_field_tag "verification_documents[]", type: :file, multiple: true %>
</span>
<div class="actions">
<%= f.button "Save", class: "btn btn-green pad_small" %>
</div>
ビュー/考案/登録/ edit.html.erbでuser.rb
class User < ActiveRecord::Base
has_many :verification_documents
end
class VerificationDocument < ActiveRecord::Base
belongs_to :user
has_attached_file :verification_documents
validates_attachment_content_type :verification_documents, {:content_type => %w(application/pdf)}
end
verification_document.rb routes.rbを
devise_for :users,
path: '',
path_names: {sign_in: 'login', sign_out: 'logout',sign_up: 'sign-up', edit: 'profile'},
controllers: {
omniauth_callbacks: 'omniauth_callbacks',
registrations: 'registrations'
}
01私はRegistrationsController <工夫で更新アクションを行うことができますどのように
:: RegistrationsControllerとして:
def update
if @user.update(user_params)
if params[:verification_documents]
params[:verification_documents].each do |doc|
@user.verification_documents.create(verification_documents: doc)
end
end
redirect_to root_path, notice: "Updated..."
else
render :edit
end
工夫ユーザー編集アクション中にすべての時間に複数のverification_documentsをアップロードする方法は?
注:私は、複数のverification_documentsをアップロードして、ユーザープロファイルビューページ内のすべての文書を表示したいgem.Butペーパークリップを使って工夫のユーザーテーブルに1 verification_documentを成功裏にアップロードしました。私の要件は、 Rails Devise - Register User with Associated Modelと非常によく似ていますが、代わりに、ここで私は、複数の検証確認書類をアップロードしたいアドレス属性の
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:fullname, :subscribe])
devise_parameter_sanitizer.permit(:account_update, keys: [:fullname, :reset_password_token, :verification_documents])
end
:
は、私は単一のドキュメントのアップロードのためのApplicationControllerにして以下の行を追加しましたverify_documentsは、deviseユーザーを更新しながらモデル化します。
助言は高く評価されています。アドバンスでよろしくお願いします。
使用_accepts_nested_attributes_for_における真:
使用すると、1つのファイルを追加することができますが、複数のファイルのアップロード中に問題に直面した場合、おそらくその理由は、レールはマルチパートの追加ができませんでしたです.erb_ファイルは_fields_for_を使用して複数のファイルをアップロードします。 http://stackoverflow.com/questions/13506735/rails-has-many-through-nested-form#answer-21060278 –
複数のファイルをアップロードするには、ネストフォームref:http://stackoverflow.com/を使用する必要があります。質問/ 24597721/rails-4-multiple-image-upload-using-paperclip –