I'm having problem with Rails plugin attachment_fu. On every upload, I get validation error
Size is not included in the list
I'm currently using
Rails 2.3.3
Ruby 1.8.6
The only thing I found about this problem is quite outdated discussion, which didn't help much.
Is there any solution to this problem?
I'm using attachment_fu, because I wanted to do AJAX file upload by this tutorial, but I couldn't get past the upload problem.
edit: I find only one solution that works, which is something like
def create
#image = Image.new(params[:image])
sleep 2 # for windows to catch up
#image.save ...
but I don't really like doing it this way
I think what you're really doing there is giving it time for the image processor (Rmagick or ImageScience or whatever you have hooked up) to work.
If you are are creating lots of different sizes at upload, reducing those might help.
Also, in my own experience everything runs much slower in my dev environment than it does in actual production, you may not need the hard coded delay in production.
Related
I am trying to implement ajax file upload using Valums file uploader plugin( https://github.com/valums/file-uploader ), paperclip is doing the image processing for me and helping me in cropping it.
I know many you out there would wonder why I am using this config of Rails 2.0.2.. its mainly for project specific purposes..
I am still a newbie with just around 5 months of experience in Rails..
The overall objective I am trying to meet by using this plugin is to get ajax file upload + ajax display working for me.
Firstly I am trying to make sure that the image which is passed as a parameter and the appropriate processing takes place so that the image is saved in the DB.
The main challenge here for me at least is combining Rails(paperclip.. being the major part of it) + Valums file uploader .
With the help of different search queries in Google, I have finally found something that could really help my case:-
This( http://mooooooooooo.wordpress.com/2010/12/03/paperclip-valums%E2%80%99s-file-uploader-and-middleware-continued/ ) is a blog which pretty much does just what I want it to do..
If you can spare some time reading this blog , you would find that the bloggers ("moortens")
approach is to make use of middleware and invoke the same through initializers..
I am pretty sure this blog is written some time after Rails 2.3.x came into existence.. and since I am still a newbie (please bear with me being a novice) and would have to make similar changes for my dev env which is Rails 2.0.2.. I am kinda lost.. figuring out how would I have to call the "raw_file_upload.rb" for me to get things working...
Kindly help me on this..
Thank you very much..
I am trying to use attachment_fu + image science on jRuby-1.5.2 and Rails 3. I have followed the attachment_fu docs. However, when I upload the form form the browser, i get an error on validate_as_attachment saying size cannot be blank. This is what the log says
size can't be blank translation missing: en.activerecord.errors.messages.inclusion
when I modify the plugin to forget size check or not add validate_as_attachment check, an entry is made in the DB table but the actual file is not transfered.
Can anyone please guide me, Also is there a Rails3 compatible plugin available.
Thanks for the help
AttachmentFu is rather old. I don't know if it's still being maintained actively.
The alternatives that pop into mind are Paperclip and Carrierwave. Paperclip is the older one, good, but feels a bit dated. Carrierwave feels more in sync with Rails 3 and I've been hearing a lot of great things about it.
You need to add to your config/locales/en.yml file something like
en:
activerecord:
errors:
messages:
inclusion: "Attachment"
I suggest you change your attachment_fu to be a gem,
if you haven't done it yet, add this on your Gemfile:
git "https://github.com/pothoven/attachment_fu.git" do
gem 'pothoven-attachment_fu'
end
Because this version I'm providing the link here has the patch for making it work on rails 3 and 4.
This error you are getting happens normally when you have compatibility issues.
After updating your attachment_fu then make sure that, whenever you instantiate a new image you do something like this:
image = YourImageModel.new()
image.uploaded_data = image_data_here
If you check on the implementation, the signature has changed, that's why you should change the initializations of your image models to be like this
OK so I'm looking for a good image uploading gem that is Rails 3 compatible and has no dependencies. I was using attachment_fu, but it's Rails 3 compatibility seems to be in question. And I really wanted to use Paperclip, but it has an image majick dependency. I'm having a hard time finding other alternatives...
Stupid question #1: Shouldnt Rails have some "official" image uploading scheme thats baked into the framework? Every web app will need it at some point, and hunting around every time for some questionable third-party way of doing this gets old after awhile.
Stupid question #2: Why can't Paperclip have a no-dependency mode that doesnt make thumbnails or resize, and just stores images as they are uploaded?
As someone who has Rails with Paperclip running on both Linux, Mac and Windows, I can tell you: installing ImageMagic (or whatever spelling is) is not a problem.
In fact, my old linux hosting already had it, Mac laptop, IIRC, too. I expected some problems installing it on windows, but had to just download installer and specify correct path in rails. No problem whatsoever.
So, in your place, I would really give it a try.
edit
There's also a number of file upload plugins for Rails, but I didn't use them and can't really give advice there. Google will give you examples.
I am developing my first rails site (yup, i am a rails idiot).
I'm writing a blog, and i got to the comments part.
I installed acts-as-commentable-with-threading ( GitHub ), i made and ran the migration like the install instructions said.
I have added acts_as_commentable to my Posts model and i have a Comments controller
When i add
#comment = Comment.build_from(params[:id],1, params[:body] )
I get the error.
undefined method `build_from' for #
Clearly i am doing something terribly wrong, and i don't really get the example. What should i be feeding to build_from? Can somebody explain this plugin step by step? :)
Or is there an easier way to get simple threaded comments?
Did you by chance define your own comment model? If so that is going to completely override the model from the plugin that defines build_from in the first place. I ended up getting around this by creating a module with the extra stuff I wanted then creating an initializer to include it, which works perfectly.
As an aside, the first parameter to build_from needs to be the actual commentable object the comment is to be connected to, not just an id.
I'm currently using this plugin in production and can assure you it works :)
Besides the reason of not restarting server (btw you shouldn't use nginx + passenger for development, simple mongrel or thin will do the job better in this case) I can think of two more:
You didn't install plugin (or something wrong happened during installing). However this is unlikely as you could run migration ok right?
You have comment model in app/models and rails doesn't load it from plugin. In this case you might want to try requiring file with plain old require.
I'm running Rails 2.2.2. I've read a few articles about ruby-prof and profiling a rails app. And I'm confused as to how things are really working.
I was originally using this tutorial
http://snippets.aktagon.com/snippets/255-How-to-profile-your-Rails-and-Ruby-applications-with-ruby-prof
to profile my app, and it works. This involves writing your own profile environment and running > RAILS_ENV=profiling ./script/performance/request -n 100 profiling/homepage.rb
So here's my confusion. Somehow, this runs ruby-prof and opens up all the stats etc, but I can't see anywhere where ruby-prof is ever actually called.
So then I read further, and it seems 2.2.2 has benchmarking/profiling built in. So I write a test file in the performance section like so
require 'test_helper'
require 'performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionController::PerformanceTest
def test_worksheet
get '/reduction/worksheet'
end
end
and run
rake test:profile
Is this equivalent to what I was doing above, but just now it's integrated into the whole rails framework?
My next question is this. The original script ouput a flat file and html file, but I couldn't figure out how to also get a tree file automatically to open up with KCacheGrind, or in my case MacCallGrind. Can I add formats into my script call?
Edit: running the scripts through rake test seem to actually produce a tree file, great. Mac CallGrind however seems to hang when trying to parse it. Anyone know other tools for viewing these tree files?
Turns out, it's exactly the same, I must have been reading an old tutorial. All the benchmarking and profiling is now in Rails which is awesome. And it outputs txt,html and tree files, also awesome. Now if Only MacCallGrind would work, there's no way I'm installing the 4gb of KDE packages needed just to view a tree file.
Brad, you should contact the author of MacCallGrind and see if there's an update, or whether he/she has a fix for your files.
Oh that's right, that's me. Please email at richard at symbol aggmedia.net, as there is an update about to come out, and I'd love to have Ruby/Rails support available.