0

現在、私はフォームに画像アップロードフィールドが追加されたモデル 'Locations'を持っています。私が行ったら、「既存の場所を更新したり、新しい場所を追加しても画像を正しくアップロードして表示しますが、入力フィールドは保存されません」Paperclipが追加されました - Nowモデルは更新を受け入れません

アップロード写真を削除するとフィールドが必要な場合は、すべてが更新され、正しく保存されます。画像が存在するときに問題が発生しても、画像は保存されますが、残りのフィールドは保存されません。

起こっ?

Locations.rb

class Location < ActiveRecord::Base 

    belongs_to :region 
    has_many :spots 


    validates_attachment_size :photo, :less_than => 5.megabytes 
    validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png'] 

    has_attached_file :photo, 
       :styles => { :thumb => "150x150#", :medium => "200x200#"}, 
       :path => ":attachment/:id/:style.:extension", 
       :s3_domain_url => "adsimgstore.s3.amazonaws.com", 
       :storage => :s3, 
       :s3_credentials => Rails.root.join("config/s3.yml"), 
       :bucket => 'adsimgstore', 
       :s3_permissions => :public_read, 
       :convert_options => { :all => "-auto-orient" } 


    attr_accessible :locations, :photo, :photo_file_name, :photo_content_type, :photo_file_size,  :photo_updated_at 
end 

フォーム

<%= form_for (@location), :html => { :multipart => true } do |f| %> 
    <% if @location.errors.any? %> 
    <div id="error_explanation"> 
    <h2><%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:</h2> 

    <ul> 
    <% @location.errors.full_messages.each do |msg| %> 
    <li><%= msg %></li> 
    <% end %> 
    </ul> 
</div> 
<div class="field"> 
    <%= f.label :name %><br /> 
    <%= f.text_field :name %> 
</div> 

<div class="field"> 
    <%= f.label :network_id %><br /> 
    <%= f.text_field :network_id %> 
</div> 

<div class="field"> 
    <%= f.label :region_id %><br /> 
    <%= f.text_field :region_id %> 
</div> 

<div class="field"> 
    <%= f.label :spot_duration %><br /> 
    <%= f.text_field :spot_duration %> 
</div> 

<div class="field"> 
    <%= f.label :frequency %><br /> 
<%= f.text_field :frequency %> 
</div> 

<div class="field"> 
    <%= f.label :screen_count %><br /> 
    <%= f.text_field :screen_count %> 
</div> 

<div class="field"> 
    <%= f.label :ad_size %><br /> 
    <%= f.text_field :ad_size %> 
</div> 

<div class="field"> 
    <%= f.label :ad_type %><br /> 
    <%= f.text_field :ad_type %> 
</div> 

<div class="field"> 
    <%= f.label :impressions %><br /> 
    <%= f.text_field :impressions %> 
</div> 

<div class="field"> 
    <%= f.label :rate_card %><br /> 
    <%= f.text_field :rate_card %> 
</div> 

<div class="field"> 
    <%= f.file_field :photo %> 
</div> 

<div class="field"> 
    <td><%= image_tag @location.photo.url(:thumb) %></td> 
</div> 

<div class="actions"> 
    <%= f.submit %> 
</div> 
<% end %> 
+0

をコメントしてみましたか? – Antoine

+0

Postを更新しました。:写真のフィールドは、後でPaperclip経由でモデルに「追加」されました。現在のテーブルが自分自身と関連していないかどうかは分かりません:photo – RubyNewbie

答えて

0

はあなたがモデルとフォームをコピーすることができますラインに

attr_accessible :locations, :photo, :photo_file_name, :photo_content_type, :photo_file_size,  :photo_updated_at 
+0

これはうまくいきました!ありがとう! – RubyNewbie

関連する問題