如何确定在控制器操作中渲染哪个视图

发布于 2024-09-17 18:27:10 字数 282 浏览 4 评论 0原文

好吧,我对如何实现这一目标有一些不同的想法,但我想我会在这里问,以防有人有更好的解决方案。

我有一个 SessionsController,它有一个登录视图和一个 widget_login 视图。我想知道如何确定在 SessionsController 的新操作中呈现哪个视图。

现在,一切都使用标准登录视图。如果请求来自我的小部件(reviewscontroller),它上面有一个“登录”链接,我希望能够渲染 widget_login 视图。如果可能的话,我不想使用引荐来源网址来确定这一点。

谢谢

Okay, I have a few different of ideas of how I would achieve this, but thought I would ask here in case someone has a better solution.

I have a SessionsController that has a login view and a widget_login view. I was wondering how to go about determining which view to render in the new action of SessionsController.

Right now, everything uses the standard login view. I was hoping to be able to render the widget_login view instead if the request is coming from my widget (reviewscontroller) which has a "Sign in" link on it. I don't want to use the referrer to determine this if possible.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窗影残 2024-09-24 18:27:10

在没有看到您的代码的情况下不确定这是否可行,但是像这样的事情怎么样:

respond_to do |format|
    format.html { render(:action => 'new') }
    format.widget { render(:action => 'widget_login') }
end

然后在您的小部件中链接到 new.widget

Not sure if this is feasible without seeing your code, but how about something like this:

respond_to do |format|
    format.html { render(:action => 'new') }
    format.widget { render(:action => 'widget_login') }
end

Then in your widget link to new.widget.

迷荒 2024-09-24 18:27:10

在操作代码末尾:

render :layout => 'my_layout'

如果已经存在 render 调用,请修改它并添加 :layout 参数。

at the end of the action code:

render :layout => 'my_layout'

if there was already a render call, modify it adding the :layout parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文