开发者

Render template with partial

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜