我在获取一个指向控制器中正确操作的按钮时遇到问题。我的显示视图有以下按钮:
<%= button_to "Submit for Approval", {action: "submit", :id => @ecn.id} %>
<%= button_to "Close ECN", {action: "close", :id => @ecn.id}, :onclick => "return confirm('Once an ECN is closed it can no longer be edited, are you sure you want to close this ECN?')" %>
我的控制器有以下两个动作:
def submit
@ecn = Ecn.find(params[:id])
@email_list = EmailList.all
respond_to do |format|
EcnNotifier.submit_engineering(@ecn).deliver if @ecn.distribute_engineering?
EcnNotifier.submit_purchasing(@ecn).deliver if @ecn.distribute_purchasing?
EcnNotifier.submit_manufacturing(@ecn).deliver if @ecn.distribute_manufacturing?
EcnNotifier.submit_qantel(@ecn).deliver if @ecn.distribute_qantel?
EcnNotifier.submit_planning(@ecn).deliver if @ecn.distribute_planning?
format.html { redirect_to ecns_url, alert: "Ecn has been submitted for approval." }
format.json { render json: @ecns }
end
end
def close
@ecn = Ecn.find(params[:id])
@ecn = @ecn.close_status
respond_to do |format|
EcnNotifier.close_engineering(@ecn).deliver if @ecn.distribute_engineering?
format.html { redirect_to ecns_url, alert: "Ecn has been closed. A confirmation email has been sent to the appropriate personnel." }
format.json { render json: @ecns }
end
end
当我单击“提交审批”按钮时,提交操作按预期运行。当我单击“关闭 ECN”按钮时,警报按预期出现,但随后处理的是提交操作而不是关闭操作。当我单击“关闭 ECN”按钮时,我的开发日志显示以下内容:
Started POST "/ecns/index?id=34" for 127.0.0.1 at 2013-11-03 11:53:02 -0700
Processing by EcnsController#submit as HTML
...
所以我可以看到它正在调用不正确的操作。我不确定是什么原因造成的,我对路由不太了解,但这里也是我的路由文件:
Engdb::Application.routes.draw do
resources :email_lists
get 'home' => 'home#index'
get 'logout' => 'sessions#destroy'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
get "login/index"
get "sessions/new"
get "sessions/create"
get "sessions/destroy"
resources :users
get "home/index"
resources :ecns
resources :revisions
resources :drawings
resources :home
match 'ecns/index' => 'ecns#submit'
match 'ecns/index' => 'ecns#close'
我在创建这两个动作时添加了两个“匹配”行。有任何想法吗?