Tips – variable in partial defined?

Posted by AllenWei | Posted in RubyOnRails, Tips | Posted on 15-02-2010-05-2008

View Comments




<bren we use variabel in partial, we will meet constant undefined error. How to avoid?
<% if foo.nil? %>

doesn’t work

assuming variable foo
There are two ways:

  1. local_assigns will get all local variables, using local_assigns[:foo],we can get variable value, If this variable is undefined, it will return nil. Not Error.
  1. defined? method
    Using
      defined? :foo


Ads Plugin created by Jake Ruston's Wordpress Plugins - Powered by and football database.