Alex Sörensen
2006-May-04 06:05 UTC
[Rails] Problem with case / when conditional of db values
Hello *,
I have been trying to perform conditional actions in the controller
depending on values in the db - in this case, the object
''info'' and the
column ''status''. I would just like the controller to run an
action
depending on the value in the column, in this case ''OPEN'' or
''SENT'':
1. def infoupdate
2. case @info.attribute(:status)
3. when ''OPEN''
...
when ''SENT''
...
but keep getting:
''You have a nil object when you didn''t expect it!
The error occured while evaluating nil.attribute''
I believe something is wrong with my code in line 2. and I have been
trying many alternatives. Please, let me know what I am doing wrong.
Thank you,
Alex
--
Posted via http://www.ruby-forum.com/.
Hi Alex, is the @info instance variable guarenteed to be set before the controller gets to the infoupdate method? Perhaps if you set @info in a before_filter to ensure that it is available at all times. Alternatively you could make this an instance method of your model eg @info.info_update def info_update case self.status ... ... end On 5/4/06, Alex S?rensen <as@hippolime.com> wrote:> > Hello *, > > I have been trying to perform conditional actions in the controller > depending on values in the db - in this case, the object ''info'' and the > column ''status''. I would just like the controller to run an action > depending on the value in the column, in this case ''OPEN'' or ''SENT'': > > 1. def infoupdate > 2. case @info.attribute(:status) > 3. when ''OPEN'' > ... > when ''SENT'' > ... > > but keep getting: > > ''You have a nil object when you didn''t expect it! > The error occured while evaluating nil.attribute'' > > I believe something is wrong with my code in line 2. and I have been > trying many alternatives. Please, let me know what I am doing wrong. > > Thank you, > > Alex > > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060504/9082cd4d/attachment.html
Maybe Matching Threads
- Multiple actions from one form - possible?
- Initialize, instance variable....wrong number of arguments!
- [Bug 14393] New: NV11 card is not detected properly by nouveau on big-endian box
- Testing basic direct x capability
- [Bug 14567] New: Randr 1.2 fails on nv17 lvds in a Dell Inspiron 8100 ( continued from 14491)