На странице редактирования Devise я помещаю загрузчик изображений с помощью скрепки.
Если я пытаюсь поместить сюда image_tag, это возвращает ошибку, подобную этой.
NoMethodError in Registrations#edit
undefined method `photo' for #<ActionView::Helpers::FormBuilder:0x000000210752d0>
У меня есть модель User, которая используется Devise.
и у User есть одна модель UserProfile.
В UserProfile я добавил :photo к attr_accessible. Я также добавил это в модель «UserProfile», чтобы использовать скрепку.
has_attached_file :photo,
:styles => {
:thumb=> "100x100>",
:small => "400x400>" }
Мой вид редактирования
<% resource.build_user_profile if resource.user_profile.nil? %>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.fields_for :user_profile do |profile_form| %>
<div><%= profile_form.label :nickname %><br />
<%= profile_form.text_field :nickname %></div>
<div><%= profile_form.label :photo %><br />
<%= profile_form.file_field :photo %></div>
<% if profile_form.photo.exists? then %>
<%= image_tag profile_form.photo.url %>
<%= image_tag profile_form.photo.url(:thumb) %>
<%= image_tag profile_form.photo.url(:small) %>
<% end %>
<% end %>
...continue on