當我提交下面的new.html.erb時,它會跳轉到http://localhost:3000/user/new_user_by_admin
,它顯示錯誤:沒有路由與{:method =>:post}匹配「/ user/new_user_by_admin」。我想將此頁面提交到http://localhost:3000/users/new_user_by_admin
。我需要做什麼改變?用戶控制器在rails中沒有路由匹配2.3.8
<% 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("https://stackoverflow.com/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
幫助!!
請使用rake檢查:路線 –