在我的redmine插件视图中,我具有以下链接:
<%= link_to "Add", :controller => "important_user", :action => "u_edit", :u_id => user.id, :p_id => @project.id, :method => :post %>
routes.rb:
resources :important_user do
collection do
post :u_edit
end
end
和控制器:
class ImportantUserController < ApplicationController
def u_edit
puts 'edit!'
end
def index
puts 'ciao'
puts params[:p_id]
puts params[:u_id]
end
end
尽管调用了预期的u_edit
操作,但是单击链接仍会调用index
方法(我在第二时间创建该方法是为了避免AbstractController::ActionNotFound (The action 'index' could not be found for ImportantUserController)
错误)。我也尝试过使用这种链接:
<%= link_to 'Add', { :action => 'create', :u_id => user.id, :p_id => @project.id}, :method => :post %>
但是它也不起作用,返回了projects?p_id=1&u_id=1
GET404。我怎样才能使其称为所需的u_edit
动作?