Hi Luc,
I am facing the same problem loading the data from YAML and using AR to
store metrics only and final data.
I am still looking for a solution to dynamically create attributes but i
am not that the controller is the place to do that. I believe it should
be done on the model level.
Did you think about the possibility of creating a class and load the
methods into it?
Try this link to learn more about metaprogramming:
http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html
Cheers,
Luc wrote:> Hello All,
>
> I have a problem while developping an application using rails.
> I''d like to add some methods to my controller depending upon some
> parameters read from an xml file during initialisation (I hope I am
> quite clear :-) )
> Below is the code I am using:
>
> ----------------
> require ''rexml/Document''
> include REXML
>
> class MyController < ApplicationController
>
> def index
> # Xsd is a model (not ActiveRecord that is used to get
> values from an XML file
> xsd = Xsd.new("myfile.xsd")
>
> # Get main section
> @main_sections = xsd.get_main_sections
>
> # Get item for first section
> @item > xsd.get_items_per_section(@main_sections[0].to_s)
>
> # Dynamically create method for to retrieve list of
> fields for each
> main sections
> # THIS PART IS NOT WORKING
> @main_sections.each do |section|
> self.instance_eval{
> define_method("get_item_for_#{section}") {"toto"}}
> end
> end
> end
> -----------------
>
>
> While testing this, I have an error message saying that the
> define_method does not exist !!!!
> Why is this method not found ???
> I am still not sure about the instance_eval, class_eval, define_method
> I need to use.
> Do you have any clues regarding this problem ?
>
> Thanks a lot,
>
> Luc
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---