Saturday, March 22, 2008


Do you want to be able to attach files to something? I needed to do that today and I made a plugin called Gawing Attachable (translated: make_attachable). It allows you to add attachments to something you make attachable.

Yes, there are many things you can still do to this, but like they say: make something quick and fix it up later on.

Check out the README before installing.
script/plugin install

Generating a resource in the routes.rb file

When making a generator, you may want to add something to the routes.rb file. To understand this you need to know how to make generators. Take a look at Ryan Bates' Railscast on how to do this.

To add a normal resource, do it this way:

class GawingFileableGenerator < Rails::Generator::Base
def manifest
record do |m|
m.route_resources :files

If you want to add other stuff like :member or :collection, do it this way

class GawingFileableGenerator < Rails::Generator::Base
def manifest
record do |m|
route_string = ":files, :member => { :download => :get }"
def route_string.to_sym; to_s; end
def route_string.inspect; to_s; end
m.route_resources route_string

Wednesday, March 12, 2008

acts_as_state_machine: make initial state exists!

Ugh.. I tried out acts_as_state_machine and I kept getting this nil error and I had no idea why. I mean, I followed the code in properly. Here's the code in that website:

acts_as_state_machine :initial => :created, :column => 'status'

# These are all of the states for the existing system.
state :submitted
state :processing
state :nonprofit_reviewing
state :accepted

Oh... apparently, you need to add

state :created

to it as well :)

Monday, March 3, 2008

Expected User, got User; forcing to reload plugins

I made my own plugin and started getting this error. This plugin is a variation of the acts_as_voteable plugin by Juixe. I did some searching around, I found this blog post that explains the fix.

Apparently, in development mode, there are issues when it comes to reloading plugins. Because the model "Vote" in my case, or "Comment" in the blog post's case, is defined inside the plugin, Rails doesn't see that it should load it again. Anyway, better to read that post for an explanation.

What I did to fix it was add this code at the end of the environment.rb file:
 # Array of plugins with Application model dependencies.
reloadable_plugins = ["acts_as_commentable"]

# Force these plugins to reload, avoiding stale object references.
reloadable_plugins.each do |plugin_name|
reloadable_path = RAILS_ROOT + "/vendor/plugins/#{plugin_name}/lib"
See the code.