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
精彩评论