Can I check object is nill in Rails3 view?
I'm trying to display a message if no transactions found. For that, I thought in the view I could use something like <% if @current_account.transactions.nill? %> puts "No transactions yet" <% end %>
unf开发者_JAVA技巧ortunately this is not valid.
Any suggestion?
The code should be
<% if @current_account.transactions.nil? %>
and not
<% if @current_account.transactions.nill? %>
Thanks....
transactions is an array so @current_account.transactions will return an empty array which is not nil?.my suggestion is to use
@current_acccount.transactions.empty?
check
irb(main):011:0> u=User.new=> #<User id: nil, email: "",....
irb(main):012:0> u.companies=>[]
irb(main):013:0> u.companies.nil?=>false
irb(main):015:0> u.companies.empty?=>true
精彩评论