Um... incredibly bizarre situation... smokescreen?

event_behavior.rb

class EventBehavior < Behavior::Base

register ‘Event’

description = %{}

define_tags do
tag ‘event’ do |tag|
if tag.attr[‘find’]
tag.locals.event = Event.find_by_name(tag.attr[‘find’])
end

  tag.expand
end

tag 'event:name' do |tag|
  tag.locals.event.name
end

end

end

Radiant page:

<r:event find=“Celine Dion”>


Okay. So, the example above works. However… One seemingly simple
change…

event_behavior.rb

class EventBehavior < Behavior::Base

register ‘Event’

description = %{}

define_tags do
tag ‘event’ do |tag|
tag.locals.event = Event.find_by_name(tag.attr[‘find’])
tag.expand
end

tag 'event:name' do |tag|
  tag.locals.event.name
end

end

end


And everything goes to shit. I get:
You have a nil object when you didn’t expect it! The error occured while
evaluating nil.name

Hitting refresh gives me a Rails error – I assume it’s because of
Radiant’s
caching.

Since when did evaluation for truth alter the way something behaves?

Help is greatly appreciated.

  • Daniel

Update…

Looks like the query is being run twice.

My development log says…


Event Load (0.000271) SELECT * FROM events WHERE (name = ‘Celine
Dion’)
LIMIT 1
Event Columns (0.000165) SHOW FIELDS FROM events

Logger: Found record: Celine Dion

Event Load (0.000187) SELECT * FROM events WHERE (name = NULL) LIMIT 1

For whatever reason it’s doing the find twice. Any ideas?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs