Hello friendly rubyists! This is my first post, so bare with me :)
I managed to globalize Typo 4.0.0 - the static content. I made a
Translations editor menu in the admin, and it works fine for all static
content.
Now I am trying to globalize Article/Content.
I have done this:
class Article < Content
include TypoGuid
content_fields :body, :extended
translates :body, :extended
...
Now I get this error:
=> Booting WEBrick...
./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1129:in
`method_missing': undefined method `translates' for Article:Class
(NoMethodError)
from script/../config/../app/models/article.rb:8
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:140:in
`load'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:56:in
`require_or_load'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
`depend_on'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:85:in
`require_dependency'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:98:in
`const_missing'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:131:in
`const_missing'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:133:in
`const_missing'
... 20 levels...
from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
from
./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in
`require'
from
./script/../config/../vendor/rails/railties/lib/commands/server.rb:30
from script/server:3
I have very little knowledge about meta programming in ruby, but I think
it has got something to do with the way the Article ActiveRecord object
is extending the base Content class.
I tried putting the translates method in the Categories class which does
not extend the Content class and it works fine!
Can anyone help me solve this issue, it is very important!? Please help
me, I am almost cluless about this problem.
Regards,
Zarni
on 05.08.2006 13:47
on 07.08.2006 10:12
Hi Zarni, I'm not sure, but is Content a model based on ActiveRecord::Base? If not, than Article is not a model (any more) and does not define translates. The content_fields seems to a method from TypoGuid. You include the module an therefore this method exists. Am 05.08.2006 um 13:47 schrieb Zarni Worgl: > > > `load' > dependencies.rb:85:in > ./script/../config/../vendor/rails/activesupport/lib/active_support/ > from > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Railsi18n-discussion mailing list > Railsi18n-discussion@rubyforge.org > http://rubyforge.org/mailman/listinfo/railsi18n-discussion > --- Thomas Baustert - Freiberuflicher Softwarecoach fon: +49(40)411 622 35 mobil: +49(173)23 911 43 fax: +49(40)411 622 36 thomas.baustert(at)b-simple.de
on 08.08.2006 02:23
Hey Thomas!
Content is based on ActiveRecord:Base... bellow is the head of the
Content class and the content_fields method is defined in it. TypoGuid
is just a library mixin, generates unique ids. So There must be
something clashing the Globalize mixin, which i put/included in
environment.rb. The translates method is defined in
Globalize::DbTranslate. I can not see why the translates method is not
being mixed into the Content class, couse it works fine for other
classes, that don't have the content_fields method.
:) Thanks for help
require 'observer'
require 'set'
class Content < ActiveRecord::Base
include Observable
@@content_fields = Hash.new
@@html_map = Hash.new
def initialize(*args)
super(*args)
set_default_blog
end
def set_default_blog
if self.blog_id == nil or self.blog_id == 0
self.blog = Blog.default
end
end
class << self
def content_fields(*attribs)
@@content_fields[self] = ((@@content_fields[self]||[]) +
attribs).uniq
@@html_map[self] = nil
attribs.each do | field |
define_method("#{field}=") do | newval |
if self[field] != newval
changed
self[field] = newval
if html_map(field)
self[html_map(field)] = nil
end
notify_observers(self, field.to_sym)
end
self[field]
end
unless self.method_defined?("#{field}_html")
define_method("#{field}_html") do
if blog.controller
html(blog.controller, field.to_sym)
else
self["#{field}_html"]
end
end
end
end
end
...
end
Thomas Baustert wrote:
> Hi Zarni,
>
> I'm not sure, but is Content a model based on ActiveRecord::Base?
> If not, than Article is not a model (any more) and does not define
> translates.
>
> The content_fields seems to a method from TypoGuid. You include the
> module
> an therefore this method exists.
>
>
>
>
> Am 05.08.2006 um 13:47 schrieb Zarni Worgl:
>
>>
>>
>> `load'
>> dependencies.rb:85:in
>> ./script/../config/../vendor/rails/activesupport/lib/active_support/
>> from
>>
>>
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>> _______________________________________________
>> Railsi18n-discussion mailing list
>> Railsi18n-discussion@rubyforge.org
>> http://rubyforge.org/mailman/listinfo/railsi18n-discussion
>>
>
> ---
> Thomas Baustert - Freiberuflicher Softwarecoach
> fon: +49(40)411 622 35 mobil: +49(173)23 911 43
> fax: +49(40)411 622 36
> thomas.baustert(at)b-simple.de
on 08.08.2006 10:20
Hi Zarni, sorry, but then I have no idea. If you are sure it is a problem with classes that include TypoGuid you may uncomment all methods of TypoGuid an activate parts of the code one by one (maybe with some pseudo code) until you get the exception. Some work, but you know where the problem is. You may switch the statements class Article < Content translates :body, :extended include TypoGuid content_fields :body, :extended and see what happend. You can further print out all included methods using included_modules() or public_class_methods() für class method to see what in your class. May that helps :) Am 08.08.2006 um 02:23 schrieb Zarni Worgl: > > @@html_map = Hash.new > end > self[field] = newval > html(blog.controller, field.to_sym) > end >> The content_fields seems to a method from TypoGuid. You include the >>> `load' >>> Railsi18n-discussion@rubyforge.org > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Railsi18n-discussion mailing list > Railsi18n-discussion@rubyforge.org > http://rubyforge.org/mailman/listinfo/railsi18n-discussion > --- Thomas Baustert - Freiberuflicher Softwarecoach fon: +49(40)411 622 35 mobil: +49(173)23 911 43 fax: +49(40)411 622 36 thomas.baustert(at)b-simple.de