Ruby 'if' condition in rjs
I want to insert a us开发者_Go百科er 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.
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
page.insert_html :bottom, :userlist, render(:partial => "user", :locals => { :user => @row, :myid => @row.id }) unless @row.blank?
精彩评论