I am getting the following error /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1129:in `method_missing'': undefined method `directory?'' for Msg::File:Class (NoMethodError) I have a model called Msg::File in models/msg/file.rb, and I have a file in lib/msg/helper.rb which references to both Msg::File and File.directory? How do I help activerecord to use the system File instead of my activerecord object Msg::File? -- Posted via http://www.ruby-forum.com/.
I might be way off here (i''ve only had to do that kind of thing once) but try ::File.directory? Cheers, Dan
Hi Dan, Thanks for the suggestion. Unfortunately, same error. -- Posted via http://www.ruby-forum.com/.
Hi Thomas, you''ve got me wondering whether you''ve correctly defined your Msg::File class.... in msg/file.rb does it look like this? class Msg::File < ActiveRecord::Base end or this? module Msg class File < ActiveRecord::Base end end Either of those ought to work. Regards, Trevor -- Trevor Squires http://somethinglearned.com On 18-Apr-06, at 9:12 PM, Thomas Kwan wrote:> Hi Dan, > > Thanks for the suggestion. Unfortunately, same error. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Trevor, I have my class defined as class Msg::File < ActiveRecord::Base set_table_name "msg_files" end I remember I''ve read from somewhere that the model name (i.e. File) cannot be the same as the module name of your controller. I saw that happened before. But in this case, this model name is the same as one of the module name of a system library. -- Posted via http://www.ruby-forum.com/.
Hey, On 18-Apr-06, at 11:05 PM, Thomas Kwan wrote:> Trevor, > > I have my class defined as > > class Msg::File < ActiveRecord::Base > set_table_name "msg_files" > end >I tried this out here (rails 1.1) and in the console it works fine for me in the console: |>> Msg::File.new |=> #<Msg::File:0x2213650 @new_record=true, @attributes={"name"=>""}> |>> File.directory? ''/tmp/'' |=> true> > I remember I''ve read from somewhere that the model name (i.e. File) > cannot be the same as the module name of your controller. I saw > that happened before. But in this case, this model name is the > same as one of the module name of a system library. >The controller-vs-model name clashes shouldn''t be the issue here. I know it''s already been suggested but my instinct is to think you''ve got a bit of code that''s interpreting a bare ''File'' as ''Msg::File'' when you really mean ''::File''. Check each line of the backtrace to make sure you haven''t missed something. Trev -- Trevor Squires http://somethinglearned.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060419/6df9cee1/attachment.html
Trevor, I am on rails 1.1 also. I can reproduce the problem by doing the following: - Create app/models/msg/file.rb class Msg::File < ActiveRecord::Base set_table_name "msg_files" end - Create app/lib/msg/my_helper.rb require ''msg/file'' module Msg class MyHelper def initialize() end def reproduce_error Msg::File.new File.directory? ''tmp'' end end end - Create app/script/driver.rb require ''msg/my_helper'' helper = Msg::MyHelper.new helper.reproduce_error Thanks -- Posted via http://www.ruby-forum.com/.
Hi Thomas, change your code as follows: def reproduce_error Msg::File.new ::File.directory? ''/tmp'' end Any code that lives in the Msg module *must* use the fully qualified name for ::File or Msg::File to avoid clashes. Let me know how you get on, Trevor -- Trevor Squires http://somethinglearned.com On 19-Apr-06, at 7:37 AM, Thomas Kwan wrote:> Trevor, > > I am on rails 1.1 also. I can reproduce the problem by doing the > following: > > - Create app/models/msg/file.rb > > class Msg::File < ActiveRecord::Base > set_table_name "msg_files" > end > > - Create app/lib/msg/my_helper.rb > > require ''msg/file'' > module Msg > class MyHelper > > def initialize() > end > > def reproduce_error > Msg::File.new > File.directory? ''tmp'' > end > > end > end > > - Create app/script/driver.rb > > require ''msg/my_helper'' > > helper = Msg::MyHelper.new > helper.reproduce_error > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Maybe Matching Threads
- Execute code when an inheritance happens, or disabling STI
- I can''t get rails to see my plugin. How can I this?
- Create a helper for models and views?
- rake create_sessions_table, does not create session table
- validations without AR - going crazy trying to find link