开发者

Ruby 'if' condition in rjs

开发者 https://www.devze.com 2022-12-28 19:10 出处:网络
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?

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?
0

精彩评论

暂无评论...
验证码 换一张
取 消