[英]Ruby on Rails Undefined method
我打算創建到控制器動作的鏈接update_heimdall
這里是代碼:
app/controller/admins_controller
:
def heimdall
@headline = "Heimdall"
@users = User.where(deleted_at: nil)
authorize @users
@focusUser = params['users'].blank? ? current_user : User.find(params['users'])
heim = Heimdall.new
@cards = heim.get_cards(@focusUser.trello_id, @focusUser.trello_access_token, @focusUser.trello_secret_token)
end
def update_heimdall
@user = params['users'].blank? ? current_user : User.find(params['users'])
authorize @user
heim = Heimdall.new
heim.update_cards(@user.trello_id, @user.trello_access_token, @user.trello_secret_token)
end
app/views/admins/heimdall.html.rb
:
<%= link_to "Odśwież", update_heimdall(), class: "btn btn-warning" %>
我也附上了來自rails route命令的清單:
heimdall GET /heimdall(.:format) admins#heimdall
update_heimdall GET /heimdall/update_heimdall/:id(.:format) admins#update_heimdall
不幸的是,此代碼導致以下錯誤:
未定義的方法“ update_heimdall”。
像在代碼中一樣,將heim轉換為實例變量@heim
以便可以在視圖中訪問它。 然后在操作路徑中指定對象。
當您執行rake routes
您將獲得所有paths
在左側
heimdall GET /heimdall(.:format) admins#heimdall
update_heimdall GET /heimdall/update_heimdall/:id(.:format) admins#update_heimdall
因此您的代碼應為:
<%= link_to "Odśwież", update_heimdall_path(@heim), class: "btn btn-warning" %>
有關更多信息,您可以在rails指南上查看此ruby: http : //guides.rubyonrails.org/getting_started.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.