In Ruby 1.9 Symbol can receive [] and convert to a string and then
index. I''ve confirmed this works as expected in the Rails console and
irb.
I have a model with a method_missing method defined. Like this:
def method_missing(name, *args, &block)
if name[-1] == ''=''
# Do some stuff and perhaps return
end
super
end
This throws: undefined method ''[]'' for :title:Symbol
(NoMethodError)
''title'' is one of the model''s attributes that is
getting sent to the
model in a view.
Does Rails monkey with Symbol somewhere and undefine []?
I''m stumped.
stuart.coyle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Jul-07 13:37 UTC
Re: Symbol[int] not working as expected.
Problem solved... irb, script/console were running ruby 1.9.1 All my tests and specs running on 1.8.6 ....that''s not good. Found with a spec: it "should be running Ruby 1.9.1" do RUBY_VERSION.should == "1.9.1" end On 07/07/2009 11:07pm, "stuart.coyle" <stuart.coyle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In Ruby 1.9 Symbol can receive [] and convert to a string and then> index. I''ve confirmed this works as expected in the Rails console and> irb.> I have a model with a method_missing method defined. Like this:> def method_missing(name, *args, &block)> if name[-1] == ''=''> # Do some stuff and perhaps return> end> super> end> This throws: undefined method ''[]'' for :title:Symbol (NoMethodError)> ''title'' is one of the model''s attributes that is getting sent to the> model in a view.> Does Rails monkey with Symbol somewhere and undefine []?> I''m stumped.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---