开发者

Render template with partial

开发者 https://www.devze.com 2023-01-30 07:07 出处:网络
I use this code in my app\\views\\pages\\home.html.erb file <%= render :template => \'users/new\' %>

I use this code in my app\views\pages\home.html.erb file

<%= render :template => 'users/new' %>

I use开发者_JAVA百科 this code in my app\views\users\new.html.erb file

<%= render :partial => 'users/form' %>

Showing the "Home Page" I get this error:

NoMethodError in Pages#home

undefined method `model_name' for NilClass:Class

Extracted source (around line #1):

1: <%= form_for(@user) do |f| %>

2: <% if @user.errors.any? %>

...

I read this, but it does not work. What can I do to render template with "sub-partial" correctly?


In your PagesController#home() method, you'll need to set @user -- probably with:

@user = User.new
0

精彩评论

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