-1
我試圖通過在用戶控制器中使用方法(abc
)遠程更新設備用戶記錄的某些屬性。Rails:未定義的方法`abc_users_path'
路線
devise_for :users, controllers: { confirmations: "users/confirmations", omniauth_callbacks: "users/omniauth_callbacks" }
resources :users, only: [:index, :show, :abc] do
get "/abc" => "users#abc"
end
用戶控制器
def abc
user = user.find(params[:id])
params[:abc].each do |key, value|
user.key = value
end
user.save!
respond_to do |format|
format.html { redirect_back(fallback_location: root_path) }
format.js # render users/abc.js.erb
end
end
查看
= link_to(abc_users_path(current_user, abc: true), remote: true) do
ABC
拋出的錯誤:
NoMethodError in Controller#method
undefined method `abc_users_path' for #<#:0xc2ee630>
我申明每個答案!
如果您不使用rails 5.0+,那麼該命令將是'rake routes' –