У меня проблема с обновлением изображения, аватара пользователя. Я использую CarrierWave и имею две модели: profile
и user
.
На странице user#show
у меня есть форма для profile
, в которой есть file_field
. Профиль принадлежит Пользователю. Вот форма:
<%= form_for @user.profile do |f| %>
<%= f.file_field :avatar %><br/>
<%= f.submit "Change Avatar" %><br/>
<% end %>
После отправки изображение не обновляется. В логах сервера я вижу:
Processing by ProfilesController#update as HTML Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"lHbhHK9SLIiTUuBJAAUyz0CSSC1tUhbE0oD2An2QEEY=",
"profile"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007fa60ff43b40
@original_filename="P1010056.JPG", @content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"profile[avatar]\";
filename=\"P1010056.JPG\"\r\nContent-Type: image/jpeg\r\n",
@tempfile=#<File:/var/folders/kq/gjn7ljfx1wx418ptwnbb46vr0000gn/T/RackMultipart20120213-2399-sm0m9c>>},
"commit"=>"Change Avatar", "id"=>"1"}
Это действие по обновлению моего профиля:
def update
@profile = current_user.profile
if @profile.update_attributes(params[:profile])
redirect_to user_path(current_user)
end
end
Что я делаю не так?