Deviseの編集ページに、クリップを使った画像アップローダーを配置しています。
ここに image_tag を入れようとすると、このようにエラーが返されます。
NoMethodError in Registrations#edit
undefined method `photo' for #<ActionView::Helpers::FormBuilder:0x000000210752d0>
Deviseで使用される「ユーザー」モデルがあります。
User には 1 つの「UserProfile」モデルがあります。
「UserProfile」で、attr_accessible に :photo を追加しました。ペーパークリップを使用するために、これを「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