Hello all,

I'm tinkering around with method_missing, and have run into a problem.

I'm trying to create virtual columns so plugins like formtastic work
properly with this model.

I plan on wrapping all attributes related to this project with the
name "option_*", as such I have changed method missing to the
following:

...
  def method_missing(method, *arguments, &block)
    logger.info "Looking for #{method}"
    if method.to_s =~ /option_(.+)/
      process_option_method(method, *arguments)
    else
      super
    end
  end
  def process_option_method(method, *arguments)
    if method.to_s =~ /option_(.+)=/
      return set_option($1, *arguments.first)
    elsif method.to_s =~ /option_(.+)/
      return get_option($1, false)
    end
  end
..

now get_option and set_option work as expected, and the setter part of
the above code also works. However when a form is submitted with a
field option_foo i get the error "unknown attribute: option_foo".

The logger input above indicates that method_missing is not called,
and the stack trace confirms this. The stack trace indicates that when
update_attributes is called, it never gets around to method missing.

So, I'm stuck. What would be the proper way to accomplish a dynamic
setter method?

Brian

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to