我已经阅读了几十篇关于没有方法错误的类似帖子,但我找不到能解决问题的帖子。我收到了NoMethodError in Users#new
错误消息"未定义的方法' form_group_tag'对于#<#:0x007f8dbd7d97e8>"。
我的new.html.erb文件代码为:
<!-- begin snippet -->
<%= form_for @user do |f| %>
<% if @user.errors.any? %>
<div class="alert alert-danger">
<h4><%= pluralize(@user.errors.count, "error") %>.</h4>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= form_group_tag(@user.errors[:name]) do %>
<%= f.label :name %>
<%= f.text_field :name, autofocus: true, class: 'form-control', placeholder: "Enter name" %>
<% end %>
<%= form_group_tag(@user.errors[:email]) do %>
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control', placeholder: "Enter email" %>
<% end %>
<%= form_group_tag(@user.errors[:password]) do %>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control', placeholder: "Enter password" %>
<% end %>
<%= form_group_tag(@user.errors[:password_confirmation]) do %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: 'form-control', placeholder: "Enter password confirmation" %>
<% end %>
<div class="form-group">
<%= f.submit "Sign Up", class: 'btn btn-success' %>
</div>
<% end %>
&#13;
我得到的错误是: &#34;未定义的方法&#39; form_group_tag&#39;对于#&lt;#:0x007f8dbd7d97e8&gt;&#34;
我的用户控制器是:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new
@user.name = params[:user][:name]
@user.email = params[:user][:email]
@user.password = params[:user][:password]
@user.password_confirmation = params[:user][:password_confirmation]
if @user.save
flash[:notice] = "Welcome to Genetic Golf #{@user.name}!"
redirect_to root_path
else
flash.now[:alert] = "There was an error creating your account. Please try again."
render :new
end
end
end
在我的routes.rb中我有
resources :users, only: [:new, :create]