[Rails] paper clip plugin validation fails
hallo friends i developpeda photo uploader using paper clip plugin
its working quite well , but one problem is its able to upload all
kinds of file. see i want only png,gif,jpeg and should show error
message if validation fails.here if i applied validations in the model
the result is errors like this
ArgumentError (too few arguments):
app/controllers/images_controller.rb:63:in `format'
app/controllers/images_controller.rb:63:in `create'
vendor/plugins/haml/rails/./lib/sass/plugin/rails.rb:19:in `process'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
-e:4:in `load'
-e:4
here are my controller code
def create
@user = @current_user.id
puts"usertrrrr"+@user.inspect
@image = Image.new(params[:image].merge(:user_id => @user))
if @image.save_with_permissions(params[:users])
puts"if saved"
else
puts"if not saved"
format.js # create.js.rjs
format.xml { render :xml => @image.errors, :status =>
:unprocessable_entity }
puts"hiiiiiiiiiiiiiiiiii"+@image.errors.inspect
end
#puts"check the srrors are"+@image.errors.inspect
responds_to_parent { render }
end
here is the model validation
validates_attachment_content_type :picture,
:content_type=>['image/jpeg', 'image/png', 'image/gif'], :message =>
:missing_content_type
or
validates_format_of :picture,:allow_blank=>true, :with =>
%r{\.(gif|jpg|png|jpeg|bmp)$}i,:message => "Invalid file extension for
teaser image. Please upload files with the following extensions only :
.jpg, .jpeg, .png, .gif, .bmp"
can anyone help me to sort out this issue.please help me
Thanks In advance
--
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home