在我的应用程序中,我有自动发送电子邮件提醒应用程序完成面试过程中的下一步。电子邮件有一个退出链接,点击后,该链接将触发控制器动作,触发状态机事件以将其状态更改为opted_out
。该链接不工作,并从本地主机控制台,这似乎是因为链接仍然产生GET请求,没有路由(错误是ActionController::RoutingError (Not Found):
)。Rails 3.2`link_to`(在电子邮件中)'method::put`仍然产生GET请求
这里是显示不想要的GET请求控制台:
Started GET "/worker/application/opt_out.1" for 10.0.2.2 at 2014-08-29 17:08:06 +0000
Processing by LandingController#show as
Parameters: {"category"=>"worker/application", "location"=>"opt_out"}
这里是链接:
link_to 'stop getting these reminders', opt_out_worker_application_url(@worker), method: :put, style: 'background-color: #fff; color: #56A0D3; display: inline-block; margin-bottom: 5px; margin: 0px; padding: 0px; text-decoration: none'
这里是所有的worker
命名空间的路线:
# routes.rb
namespace :worker do
resource :application, only: [:create, :new, :show] do
member do
put 'opt_out' => 'application#opt_out'
end
end
resources :jobs do
member do
post 'compete' => 'jobs#compete'
delete 'compete' => 'jobs#withdraw'
end
resources :comments, only: [:create]
resources :timesheets, only: [:create, :new, :show]
end
resources :banks, only: [:create, :new, :destroy]
scope 'money' do
root to: 'money#index', as: 'money'
post 'withdraw' => 'money#withdraw', as: 'money_withdraw'
end
get 'profile' => 'profiles#show'
root to: 'jobs#index'
end
以下是控制器操作:
# applications_controller.rb
def opt_out
@worker = Worker.find(params[:id])
if @worker.interview_requested? or @worker.onboarding_requested?
if @worker.fire_state_event(:opt_out)
AdminsMailer.sweeper_opted_out(@worker.id)
redirect_to root_url, notice: "You have successfully opted out of the application process. We're sorry to see you go, and hope you'll consider returning in the future!"
else
redirect_to root_url, alert: "There was a problem. Please contact Support if you need further assistance."
end
else
redirect_to root_url, alert: "There was a problem. Please contact Support if you need further assistance."
end
end
这里是rake routes
:
opt_out_worker_application PUT /worker/application/opt_out(.:format) worker/application#opt_out
worker_application POST /worker/application(.:format) worker/applications#create
new_worker_application GET /worker/application/new(.:format) worker/applications#new
GET /worker/application(.:format) worker/applications#show
'link_to'怎么可能是'PUT'? 'link_to'不能有字段/形式,所以将它作为'PUT'或'POST'是什么意思? – RAJ 2014-08-29 17:15:38
我没有关注你,因为你问了两个似乎至少是半修辞的问题。你对我应该改变什么有什么建议吗? – sixty4bit 2014-08-29 17:18:10
为什么你想link_to as PUT? – RAJ 2014-08-29 17:21:13