Daniel Müller-briel
2007-Nov-23 11:19 UTC
call model method out of the controller => undefined method
Hi, I''m a newby and I fight with the Rails convention - i think so. I''ve done little tools and scripts in Ruby before. I''ve successfully uploaded a textfile. And now i want to extract some filecontent to pass it into a database. My Problem: I can not start a given method of a given Model (=> Metadata.extract_content(fileuri)). The error message ''undefined method `extract_content'' for Metadata:Class'' is raised. But the method is still there!? My Controller Action: ######################################### def upload @schema_file = params[:schema_file] @file = File.new(File.join("D:","testfile.txt"), "wb") if @schema_file @file << @schema_file.read end @file.close Metadata.extract_content(@file) # <- error causing line render :action => ''load'' end ######################################### My Model: ######################################### class Metadata < ActiveRecord::Base def extract_content file # logic end end ######################################### Apart from this i''m not allowed to call any extern method out of the controller. (?) - How can i call extern method? - Are there any RoR conventions or constrains for this topic? Thanks for helping. Daniel -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2007-Nov-23 11:23 UTC
Re: call model method out of the controller => undefined met
use: class Metadata ... def self.extract_content ... to define it on class level your version would have to be called with an object: @thing = Metadata.new(...) @thing.extract_content(@file) -- 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 -~----------~----~----~----~------~----~------~--~---
Daniel Müller-Briel
2007-Nov-23 11:36 UTC
Re: call model method out of the controller => undefined met
Thanks. Problem solved. -- 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 -~----------~----~----~----~------~----~------~--~---
Thomas Schulze
2007-Dec-04 16:03 UTC
AW: [Rails] Re: call model method out of the controller => undefined met
Dear reader, please have a look at our new database for students www.spirofrog.de – Start Your Global Career. We want to help students from Germany and Europe to do an internship in foreign countries and international students to find suitable positions in German and European companies. Additionally, we also place students in jobs for Young Professionals. This service is sponsored by companies = Students have free access Our customers include TVM Capital, European Investors Inc., Ebay, and many more. We would also like to post job offers and the company profile from your company in our database. Please do not hesitate to contact us and we will try to find you the suitable candidates or companies. Best regards, Jessica from Spirofrog – Start Your Global Career>>>Member of http://www.bicc-net.de/ <<<No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.16.13/1169 - Release Date: 03.12.2007 22:56 --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---