当我提交下面的 new.html.erb 时,http://localhost:3000/user/new_user_by_admin
它会显示错误:没有路由匹配“/user/new_user_by_admin”与 {:method=>:post}。我希望将此页面提交给http://localhost:3000/users/new_user_by_admin
. 我需要什么改变?
<% form_for :user,:url => url_for { :controller => :user ,:action => :new_user_by_admin, :method => :post } do |f| %>
<p><%= f.label :login %><br/>
<%= f.text_field :login %></p>
<p><%= f.label :name %><b`enter code here`r/>
<%= f.text_field :name %></p>
<p><%= f.label :email %><br/>
<%= f.text_field :email %></p>
<p><%= f.label :password %><br/>
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation, 'Confirm Password' %><br/>
<%= f.password_field :password_confirmation %></p>
<p><%= submit_tag 'Sign up' %></p>
<% end %>
用户控制器的代码是:
class UsersController < ApplicationController
def new_user_by_admin
@user=User.new(params[:user])
@user.save
redirect_to("/users/")
end
end
routes.rb 的代码是:
ActionController::Routing::Routes.draw do |map|
map.home '' , :controller => 'users', :action => 'index'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.register '/register', :controller => 'users', :action => 'create'
map.signup '/signup', :controller => 'users', :action => 'new'
map.adduser '/new_user_by_admin', :controller => 'users', :action => 'new_user_by_admin', :method => :post
map.resources :users
map.resource :session
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
帮助!!