我爲我的用戶控制器實現了一個名爲update_status的自定義更新函數。我需要一些路由幫助。我想要做的是更新只有管理員才能訪問的狀態。我通過用戶控制器中的編輯功能通過表單助手調用更新函數。這是我的形式助手代碼:導軌的自定義更新函數路由
但是當我點擊保存更改我得到的是這樣的錯誤
我要路由的行動,使用戶ID可以解決。
控制器動作代碼:
def update_status
if @user.update_attributes(status_params)
flash[:success] = "User updated"
redirect_to @user
else
render 'edit'
end
end
路線:
Transpub::Application.routes.draw do
resources :users do
member do
put 'update_status'
end
end
resources :papers
resources :comments
resources :reviews
resources :sessions, only: [:new, :create, :destroy]
resources :relationships, only: [:create, :destroy]
resources :comments, only: [:create, :destroy]
resources :subject_field, only: [:create, :destroy]
#get "users/new"
root "static_pages#home"
match "/signup", to: "users#new", via: "get"
match "/signin", to: "sessions#new", via: "get"
match "/signout", to: "sessions#destroy", via: "delete"
match "/help", to: "static_pages#help", via: "get"
match "/about", to: "static_pages#about", via: "get"
match "/contact", to: "static_pages#contact", via: "get"
match "/search_papers", to: "papers#index", via: "get"
match "/browse_papers", to: "papers#browse", via: "get"
發佈您的控制器代碼。 – Pavan
你可以發佈routes.rb文件中定義的路由嗎? –