I have a video model using Paperclip to store the file. The model:
class Video < ActiveRecord::Base
belongs_to :category
before_save :permalink
validates_presence_of :title
validates_presence_of :category
validates_attachment_presence :filepath, :message => ''- please,
select a file to updload''
validates_attachment_size :filepath, :less_than => 100.megabytes
validates_attachment_content_type :filepath, :content_type =>
[''video/x-flv''],
:message => ''- You can
upload only Flash movies''
has_attached_file :filepath,
:url =>
APP_CONFIG[''url'']+"/videos/inline/:id",
:path => ":rails_root/
uploads/:attachment/:id/:style/:basename.:extension"
named_scope :videos_in_category,
lambda { |category_id|
{:conditions => ["category_id = ?", category_id]}
}
private
def permalink
slug = Slug.new
self.url_slug = slug.url_friendly self.title
end
end
When I run this test:
test "should create video" do
assert_difference(''Video.count'') do
video = videos :videos_002
video.filepath = File.new("#{RAILS_ROOT}/test/fixtures/
add_file.flv")
video.filepath_content_type = ''video/x-flv''
category = categories(:intranet_administration)
post :create, :video => { :title => video.title,
:description => video.description,
:category_id => category.id,
:filepath => video.filepath,
:filepath_file_size =>
File.size("#{RAILS_ROOT}/test/fixtures/add_file.flv"),
:filepath_content_type => ''video/x-
flv'',
:url_slug => video.url_slug}
end
assert_redirected_to video_path(assigns(:video))
end
I get this message:
"Video.count" didn''t change by 1.
<2> expected but was
<1>.
I tried to understand why it is not created but I do not get any
feedback. Do you have an idea how to solve this?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Any idea how to debug? On Feb 16, 9:52 am, rtacconi <rtacc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a video model using Paperclip to store the file. The model: > > class Video < ActiveRecord::Base > belongs_to :category > before_save :permalink > > validates_presence_of :title > validates_presence_of :category > validates_attachment_presence :filepath, :message => ''- please, > select a file to updload'' > validates_attachment_size :filepath, :less_than => 100.megabytes > validates_attachment_content_type :filepath, :content_type => > [''video/x-flv''], > :message => ''- You can > upload only Flash movies'' > > has_attached_file :filepath, > :url => APP_CONFIG[''url'']+"/videos/inline/:id", > :path => ":rails_root/ > uploads/:attachment/:id/:style/:basename.:extension" > > named_scope :videos_in_category, > lambda { |category_id| > {:conditions => ["category_id = ?", category_id]} > } > > private > def permalink > slug = Slug.new > self.url_slug = slug.url_friendly self.title > end > end > > When I run this test: > > test "should create video" do > assert_difference(''Video.count'') do > video = videos :videos_002 > video.filepath = File.new("#{RAILS_ROOT}/test/fixtures/ > add_file.flv") > video.filepath_content_type = ''video/x-flv'' > category = categories(:intranet_administration) > post :create, :video => { :title => video.title, > :description => video.description, > :category_id => category.id, > :filepath => video.filepath, > :filepath_file_size => > File.size("#{RAILS_ROOT}/test/fixtures/add_file.flv"), > :filepath_content_type => ''video/x- > flv'', > :url_slug => video.url_slug} > end > > assert_redirected_to video_path(assigns(:video)) > end > > I get this message: > > "Video.count" didn''t change by 1. > <2> expected but was > <1>. > > I tried to understand why it is not created but I do not get any > feedback. Do you have an idea how to solve this? > > Thanks.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
rtacconi wrote:> Any idea how to debug?Have a look at this example help me understand paperclip. http://www.cordinc.com/blog/2009/04/multiple-attachments-with-vali.html Just i noted from your code you are not using "belongs_to :attachable" in your model video. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I will have a look thank you. On 18 Feb, 15:51, Dave Lynch <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> rtacconi wrote: > > Any idea how to debug? > > Have a look at this example help me understand paperclip. > > http://www.cordinc.com/blog/2009/04/multiple-attachments-with-vali.html > > Just i noted from your code you are not using > > "belongs_to :attachable" in your model video. > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.