0
我不知道這是如何工作的軌道,但我設置了這樣的路線:強大的參數和嵌套的路線 - Rails的4.0
resources :users do
resources :api_keys
end
(用戶has_many: api_keys
,API_KEY belongs_to: user
)
所以我當時(因爲我只在乎API密鑰),創建了以下控制器:
class ApiKeysController < ApplicationController
before_action :authenticate_user!
def index
@user = User.find(params[:user_id])
@api_key = User.apikeys
end
def create
@user = User.find(params[:user_id])
@api_key = ApiKey.new(create_new_api_key)
create_api_key(@api_key, @user)
end
def destroy
destroy_api_key
end
private
def create_new_api_key
params.require(:api_key).permit(user_attributes: [:id], :api_key)
end
end
其中規定,每一個動作之前認證用戶,指數獲取所有API密鑰BA sed用戶標識。 (備註:create_api_key(@api_key, @user)
只是一個抽象的方法,說明 - 如果我們保存,用消息重定向到user_path
,如果我們失敗了,返回到帶有錯誤消息的用戶路徑)
並銷燬,只是發現一個api鍵,銷燬它並重定向(再次與抽象)。
這是什麼問題?
create_new_api_key
方法。它嚇壞了,說:
syntax error, unexpected ')', expecting => (SyntaxError)
我認爲這是我如何傳遞用戶ID?