Pregunta

My model has attribute html. When I try to use alias_method_chain with setter html=, I get the error undefined method `name=' for class `Banner' But I use alias_method_chain with another attribute.

class Banner < ActiveRecord::Base

  def file_with_metadata_handling=(uploaded_file)
    # ...
  end

  def html_with_format_checking=(banner_html)
    # ...
  end

  # works well
  alias_method_chain :file=, :metadata_handling

  # undefined method html=
  alias_method_chain :html=, :format_checking
end

Method is defined

Banner.new.respond_to? :html=
 => true 
¿Fue útil?

Solución

Model defines attribute's getters & setters dynamically. So alias_method_chain had't found setter for attribute.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top