私は標準のデバイス編集ユーザーフォームを持っています:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, :autocomplete => "off" %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<p>Current Photo</p>
<%= image_tag @user.photo.url %>
<%= f.file_field :photo %>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<div><%= f.submit "Update" %></div>
<% end %>
さて、Rails は次の行のために明らかに不平を言います:<%= image_tag @user.photo.url %>
デバイス コントローラの編集アクションに @user がないからです。通常、 @user = current_user をコントローラーに入れるだけで完了します。
目標は、ユーザーが新しい写真をアップロードする前に、現在の写真が何であるかをユーザーに示すことです。それを行う最善の方法は何ですか?