如何在像我的主页这样的静态页面上呈现属于我的用户控制器一部分的视图? [英] How can I render a view that is a part of my user controller on a static page like my home page?

查看:33
本文介绍了如何在像我的主页这样的静态页面上呈现属于我的用户控制器一部分的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我正在构建的应用的注册表单放在应用的主页上,但是我不知道如何在我的主页上呈现视图 app/views/users/new.html.erb页.有没有一种方法可以用来完成这个任务?非常感谢!

I'm looking to place the signup form for an app I'm building on the app's home page, however I don't know how to render the view app/views/users/new.html.erb on my home page. Is there a method I can use to accomplish this? Thanks a bunch!

推荐答案

您可以使用 content_for 块,然后在您的应用程序布局中产生它.使用您的用户/新页面创建一个部分.(用户/_new).

You can use a content_for block and then yield it on your application layout. Create a partial with your users/new page. (users/_new).

在您的 homepage.html.erb 文件中添加

In your homepage.html.erb file add

 <% content_for :homepage do %>
  <%= render users/new %>
 <% end %>

然后在您的 application.html.erb 文件中添加

Then in your application.html.erb file add

  <%= yield :homepage %>

这篇关于如何在像我的主页这样的静态页面上呈现属于我的用户控制器一部分的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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