Attachment_fu issue - ruby-on-rails

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

Related

Cane with Rails

I just discovered the Cane gem but it doesn't work with Rails, there is a way to make it work with Rails?
Update
I'm using rails 3.2.1 and It doesn't produce any error message
I'm the author of this gem.
How do you mean "doesn't work"? It's possible you just write good code :) The default options aren't too strict. Can you please post the output of:
cane --style-glob '**/*.rb' --style-measure 1
This should error on every line in the project, to verify whether cane is "working". And also
find . app
When run from within your rails directory.

Paperclip + Valums ajax file upload plugin for Rails 2.0.2 and Ruby 1.8.7 Config

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..

Starting out with vote_fu

Trying my luck with the vote_fu rails plugin. The functionality looks like exactly what I need for a project of mine, but I have hit a roadblock. I have followed the github readme to the letter, installing it as a plugin.
I have put acts_as_voteable on my "Event" model and acts_as_voter on my User model.
In the console, when I try:
>> event.votes
or
>> user.votes
it successfully returns an empty array.
but when I try to do the following:
user.vote_for(event)
I get
"NoMethodError: undefined method `user_id' for #<Vote:0x7f5ed4355540>"
Any ideas? I'm probably just missing something obvious, but maybe something is missing from the plugin's readme.
Thanks.
[Update]
I created a blank application and the plugin works fine, so I think that this problem might be being caused by the use of the "desert" plugin, as my User class is split over two files. If I find the answer, I'll post it so that in the off chance someone else runs into this it may be some help.
Cheers.
Ok, I haven't found a definitive reason why this problem occurred, but I do have strong suspicions that it is due to the use of the "desert" plugin, as my User class is split over two files (the project is using the CommunityEngine plugin as a base),
Anyhow, I found a work around (something I should have tried before posting here). Instead of installing vote_fu as a plugin, I installed it as a gem. And now vote_fu seems to be humming along nicely.
So let that be a lesson to you all!
:-P

How to use acts-as-commentable-with-threading in Rails

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.

Rails plugin Attachment_fu on Windows

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.

Resources