deviseを使っている時の画像アップロード手順
views/devise/registrations/new.html.erb
にこれを追加
editにも追加する。
new.html.erb
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
edit.html.erb
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
アプリケーションコントローラーにストロングパラメーターを追加
controllers/application_controller.rb
devise_parameter_sanitizer.for(:sign_up)<< [:name, :phone_number, :image]
:image
を追加。
application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up)<< [:name, :phone_number, :image]
devise_parameter_sanitizer.for(:sign_in)<< [:name, :phone_number]
end
end
Author And Source
この問題について(deviseを使っている時の画像アップロード手順), 我々は、より多くの情報をここで見つけました https://qiita.com/Kaisyou/items/296d1fe20019511aa40a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .