Starting out with vote_fu - ruby-on-rails

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

Related

Rails 2.3.9, adding ActiveScaffold, getting in `alias_method': undefined method `number_of_pages' for class `Paginator'

I have AS (as a plugin) working in another app just fine (I dont remember this
issue...) - its also using Rails 2.3.9, on same dev box.
Now trying to add it to a new app and getting this error when running
the webrick, script/server:
/Users/kimptoc/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.9/lib/
active_support/core_ext/module/aliasing.rb:33:in `alias_method':
undefined method `number_of_pages' for class `Paginator' (NameError)
from /Users/kimptoc/.rvm/gems/ruby-1.8.7-p302/gems/
activesupport-2.3.9/lib/active_support/core_ext/module/aliasing.rb:
33:in `alias_method_chain'
from /Users/kimptoc/Documents/ruby/borisbikestats/vendor/plugins/
active_scaffold/lib/extensions/paginator_extensions.rb:9
I couldn't find any previous references to this error.
Embarassingly I dont know which version of AS I am using successfully... it says 1.2RC1 in the CHANGELOG file, but I seem to remember trying a few of the forks...(is there somewhere I can see which fork is in use...). I have tried using the the 'main' activescaffold in the new project, but it fails as above, but so does using the same plugin that is in the working project :(
Thanks in advance for any pointers as to what I am doing wrong.
Thanks,
Chris
PS Just realised that new Rails was using Rails 3 and old/working one was 2.3.9. It seems you need to use an alternate branch of AS for Rails 3, like this : https://github.com/vhochstein/active_scaffold/wiki
This is just a guess, but built in pagination was removed in Rails 2 as I recall, and you needed to install the classic_pagination plugin to get that functionality back.
I only used ActiveScaffold once, but the error there says paginator_extensions.rb ... it's probably monkey patching the old Rails paginator? Therefore the class exists but the number_of_pages method doesn't.

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.

Error while using Fetcher plugin to process incoming mail with Rails?

I'm trying to get a basic example app running that processes email. Nothing fancy, just the barest of functionality at this point. I've installed Fetcher, configured the YAML, updated the :receiver, and created an IncomingMailHandler class.
When I go to start the FetcherDaemon, I get the following error.
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant MailerDaemonFetcherDaemon::IncomingMailHandler (NameError)
I'm using Rails 2.3.2, with the latest Fetcher plugin. The IncomingMailHandler class in my models dir looks like this:
class IncomingMailHandler < ActionMailer::Base
def receive(email)
logger.info("Got a mail about: #{mail.subject}")
end
end
Help!
Ok, so basically, I'm a dumbass. I was following instructions all over the damn web, except for the mostly cut and dry explanation on github. Days later now, I just went through the motions, and boom, it worked flawlessly.
So, to anyone that finds this with the same problem (whether you were trying to follow the WAY outdated instructions on the PeepCode tutorial, or found some tips on a blog), don't be a dumbass like me. The most up-to-date info is on github.
Thanks to anyone that looked at this!
My guess is you didnt set the MailFetcher
MailFetcher.mailer_class = :incoming_mail_handler
put this in environment.rb after the RailsInitializer block.
If you want to use POP3 instead of IMAP you have to specify this there as well

acts_as_ferret multi model search not working in rails app

I am trying to solve a strange issue with ferret/acts_as_ferret
Of course I have googled and posted the question:
http://www.ruby-forum.com/topic/188570
Basically aaf works on single models with no issue. It also works on single models using the config/aaf.rb file I have setup. It even works when I do a multi-model search in the console, but within the rails app itself I get:
undefined method `ferret_rank=' for <object that has a match>
If anyone has had the same experience/problem and can shed any light I would appreciate it.
PS: I followed the following tutorial to get where I am now.
http://opensoul.org/2008/4/29/using-shared-indexes-with-acts_as_ferret
Do you have the plugin installed or just the gem? You might want to install the plugin.
I would also try rebuilding the index.
For my purposes, I switched to Solr and life is a lot easier. Sphinx is missing a lot of stuff that I need.

has_many_polymorphs tagging - works on development machine, not on production!

I'm having a weird problem, where tagging works fine on my development machine, but when I deploy to the production server, I get this error in the log:
ActionView::TemplateError (undefined method `tags' for #<Person:0x98bb9d4>) on line...
There is an entry in the production.log file that states that has_many_polymorphs is loaded, so it's not like the plugin isn't available on the production machine.
My Google-fu has failed me trying to find the answer, so if anyone knows what could be wrong it would be greatly appreciated!
Edit: I should have mentioned that on both production and development I'm using the same database. I downloaded the production one, and used it on the development machine and it works fine.
cap deploy:migrations
I've seen similar problems to this in which the polymorphic type field is not getting correctly filled in, or when there was some existing data prior to the polymorphic type tag getting added. Is person a subclass? does the _type field contain any null values on the polymorphs table?
Just stabbing in the dark here, but has_many_polymorphs doesn't natively add tagging functionality to your models. Instead, you use a generator to create a tagging extensions module that goes into lib/tagging_extensions.rb. The module file has helper methods that add tagging functions, built on top of the has_many_polymorphs base functionality.
So, is it possible that you have the plug-in installed, but not the tagging extensions file?
I spent some time with a consultant tracking this down, and eventually we discovered that for reasons unknown, the Tagging stuff just wasn't being loaded.
By adding a single line of code, just three letters, to the end of environment.rb, it was resolved. I commented it so that we'd never forget wtf was going on:
# Magic begins here.
# We need to force Rails to load the Tag record, or
# has_many_polymorphs doesn't work properly. I don't know
# if there's a better fix, but this one seems reasonable. :-/
Tag
That was it. I'm sure there's an elegant and proper solution to this, but this works. Weird.
I hope this helps someone out there.

Resources