views:

134

answers:

2

Hi,

I want to insert a user in the userlist only if the user object (@row) is not nil. How do I do the insert conditionally in an rjs template?

page.insert_html :bottom, :userlist, render(:partial => "user", :locals => { :user => @row, :myid => @row.id })

thanks much.

+3  A: 

exactly how you would do it in regular ruby

if @row
  page.insert_html(:bottom, :userlist, render(:partial => "user", :locals =>  { :user => @row, :myid => @row.id }))
end

or if you want it on one line

page.insert_html(:bottom, :userlist, render(:partial => "user", :locals =>  { :user => @row, :myid => @row.id })) if @row
tliff
A lot of people don't realize that .rjs files are actually Ruby.
tadman
+1  A: 
page.insert_html :bottom, :userlist, render(:partial => "user", :locals =>  { :user => @row, :myid => @row.id }) unless @row.blank?
Salil