开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜