我正在尝试制作用于创建用户记录的基本表单:
<%= debug(@user) %>
<%= form_for @user, url: {action: "create_user"}, html: {class: "user-create-form"} do |f| %>
<div class="form-group"><%= f.text_field :first_name, class:'form-control' %></div>
<div class="form-group"><%= f.text_field :last_name, class:'form-control' %></div>
<div class="form-group"><%= f.text_field :email, class:'form-control' %></div>
<div class="form-group"><%= f.text_field :password, class:'form-control' %></div>
<%= f.submit "Update" %>
<% end %>
在控制器中:
def create_user
@user = params[:user]
@user = User.new if !@user
end
这加载正常且没有错误,但是当我提交表单时,我收到以下错误:
NoMethodError in Admin#create_user
Showing /Applications/MAMP/htdocs/clippo2/app/views/admin/create_user.html.erb where line #6 raised:
undefined method `model_name' for ActionController::Parameters:Class
Extracted source (around line #6):
<%= form_for @user, url: {action: "create_user"}, html: {class: "user-create-form"} do |f| %>
这是我的路线:
get "admin", to: "admin#index"
get "admin/edit_user/:id", to: "admin#edit_user"
patch "admin/edit_user/:id", to: "admin#edit_user"
get "admin/create_user"
post "admin/create_user"
get "admin/delete_user"
get "access/login"
get "access/logout"
post "access/attempt_login"
root :to => 'pages#home'