如果用户在特定页面上显示部分 [英] Display Partial if user on specific page

查看:40
本文介绍了如果用户在特定页面上显示部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含以下 URL 的页面:http://www.mywebsite.com/users/profile/edit

If I have a page with the following URL: http://www.mywebsite.com/users/profile/edit

如果用户在该特定页面上,我将如何仅显示部分内容?

How would I display a partial ONLY if the user is on that particular page?

有人建议使用此代码,但语法让我感到困惑,我希望有更具体的内容.<代码><%= 渲染 :partial =>"foo/bar" 如果@conditions %>

Someone suggested this code, but the syntax confuses me and I was hoping for something more specific. <%= render :partial => "foo/bar" if @conditions %>

推荐答案

通常您会调用以在视图中显示该操作的局部.如果您有一个被多人使用的视图,那么标准过程就是您所描述的 @conditions 代表一些任意条件的地方.可能是这样的:

Usually you put the call to display the partial in the view for that action. If you have a view used by more than one, the standard procedure is as you describe where @conditions represents some arbitrary conditions. It could be like this:

<%= render(:partial => 'example') if (params[:action] == 'edit') %>

这篇关于如果用户在特定页面上显示部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆