Rails 3.2.11 Paperclip -


rails 3.2.11 paperclip polymorphic nested attachment, uploaded images never saved! maybe should add assets id every table requires images?

what stop paperclip uploading , saving files?

thank in advanced

error message:

connecting database specified database.yml started "/videos/" 31.54.205.49 @ wed may 15 06:51:33 -0500 2013 processing videoscontroller#index html   rendered videos/index.html.erb within layouts/application (111.6ms) completed 500 internal server error in 227ms  actionview::template::error (undefined method `attachment_file_name' #<video::cover:0x6929d69365c0>):     3:    <div class="video">     4:      5:   <%- video.covers.each |cover| %>             6:   <div class="video_cover"><%=link_to image_tag (cover.url(:small)), video %></div>     7:   <% end %>      8:      9:      app/models/assets.rb:4:in `__send__'   app/models/assets.rb:4:in `url'   app/views/videos/index.html.erb:6:in `_app_views_videos_index_html_erb__730847823_57814209936840'   app/views/videos/index.html.erb:5:in `_app_views_videos_index_html_erb__730847823_57814209936840'   app/views/videos/index.html.erb:1:in `each'   app/views/videos/index.html.erb:1:in `_app_views_videos_index_html_erb__730847823_57814209936840'   app/controllers/videos_controller.rb:10:in `index' 

schema:

activerecord::schema.define(:version => 20130514180732)    create_table "assets", :force => true |t|     t.datetime "created_at",               :null => false     t.datetime "updated_at",               :null => false     t.string   "type"     t.integer  "assetable_id"     t.string   "assetable_type"     t.string   "attachement_type"     t.string   "attachement_file_name"     t.string   "attachement_content_type"     t.integer  "attachement_file_size"     t.datetime "attachement_updated_at"   end    create_table "photos", :force => true |t|     t.string   "title"     t.text     "body"     t.datetime "created_at", :null => false     t.datetime "updated_at", :null => false   end    create_table "videos", :force => true |t|     t.string   "title"     t.text     "body"     t.string   "url"     t.datetime "created_at", :null => false     t.datetime "updated_at", :null => false   end  end 

models:

class assets < activerecord::base    belongs_to :assetable, :polymorphic => true   delegate :url, :to => :attachment   end      class video < activerecord::base  attr_accessible :body, :title, :url, :assets_attributes, :cover    #has_many :images, :as => :assetable, :class_name => "video::image", :dependent => :destroy   has_many :covers, :as => :assetable, :class_name => "video::cover", :dependent => :destroy    accepts_nested_attributes_for :covers, :allow_destroy => true      class video::cover < assets    has_attached_file :attachment, :styles => { :small => "300x0>", :large => "800x0>" }   end   end 

the video controller:

class videoscontroller < applicationcontroller    #load_and_authorize_resource     # /videos   # /videos.xml   def index     @videos = video.all      respond_to |format|       format.html # index.html.erb       format.xml  { render :xml => @videos }     end   end    # /videos/1   # /videos/1.xml   def show     @video = video.find(params[:id])      respond_to |format|       format.html # show.html.erb       format.xml  { render :xml => @video }     end   end    # videos/new   # /videos/new.xml   def new     @video = video.new      1.times @video.covers.build end      #40.times @video.images.build end      respond_to |format|       format.html # new.html.erb       format.xml  { render :xml => @video }     end   end    # /collections/1/edit   def edit     @video = video.find(params[:id])     1.times do@video.covers.build end      #1.times @video.images.build end    end    # post /videos   # post /videos.xml   def create     @video = video.new(params[:video])      respond_to |format|       if @video.save         format.html { redirect_to(@video, :notice => 'video created.') }         format.xml  { render :xml => @video, :status => :created, :location => @video }       else         format.html { render :action => "new" }         format.xml  { render :xml => @video.errors, :status => :unprocessable_entity }       end     end   end    # put /videos/1   # put /videos/1.xml   def update     @video = video.find(params[:id])      respond_to |format|       if @video.update_attributes(params[:video])         format.html { redirect_to(@video, :notice => 'video updated.') }         format.xml  { head :ok }       else         format.html { render :action => "edit" }         format.xml  { render :xml => @video.errors, :status => :unprocessable_entity }       end     end   end    # delete /videos/1   # delete /videos/1.xml   def destroy     @video = video.find(params[:id])     @video.destroy      respond_to |format|       format.html { redirect_to(videos_url) }       format.xml  { head :ok }     end   end end 

video form:

<div id="form_bk">  <div id="field_left">  <%= form_for @video, :html => {:multipart => true} |f| %>   <% if @video.errors.any? %>     <div id="error_explanation">       <h2><%= pluralize(@video.errors.count, "error") %> prohibited collection being saved:</h2>        <ul>       <% @video.errors.full_messages.each |msg| %>         <li><%= msg %></li>       <% end %>       </ul>     </div>   <% end %>       <div id="cover">         <br />         <h2>cover image</h2>          <%= f.fields_for :covers |cover| %>          <% if cover.object.new_record? %>         <p><%= cover.file_field :attachment %></p>          <% end %>         <% end %>          <%= f.fields_for :covers |cover| %>          <% unless cover.object.new_record? %>          <br />             <p>              <%=image_tag cover.object.url(:small) %><br />             <br /> delete cover <%= cover.check_box :_destroy %><br /><br />             </p>          <% end %>         <% end %>      </div>         <div id="form_right">    <div class="field">     <%= f.label :title %>     <%= f.text_field :title %>   </div>   <div class="field">     <%= f.label :body %><br />     <%= f.text_area :body %>   </div></div>   <div class="field">     <%= f.label :url %><br />     <%= f.text_area :url %>   </div></div>       </div>       <div class="actions">     <%= f.submit %>   </div> <% end %> <br /> </div> 

index view:

<% @videos.each |video| %>     <div class="video">    <%= video.covers.each |cover| %>          <div class="video_cover"><%=link_to image_tag (cover.url(:small)), video %></div>   <% end %>      <div class="video_title">    <%=link_to video.title, video %>    <%= video.body %>    <%= link_to 'show', video %>   <%= link_to 'edit', edit_video_path(video) %>   <%= link_to 'destroy', video, :confirm => 'are sure?', :method => :delete %>        </div>   </div>   <% end %>  <br /><br /><br /> <%= link_to 'new video', new_video_path %> 


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -