我需要添加到config.rb來解決這個問題。路由錯誤沒有路由匹配{:action =>「reset」,:controller =>「players」}
由於我非常有限的軌道知識,我設法將這種方法放在控制器中。
def reset
Player.each do |p|
p.playing = false
p.save
end
end
,並在視圖中創建
<p><%= link_to "New Game", {:action => 'reset' }%></p>
這個環節,我只是不知道要放什麼東西在routes.rb中得到這個用了餡了什麼我已經有工作。
這是我config.rb
ChooseTeams3::Application.routes.draw do
resources :players
root :to => "players#index"
get "/index" => "players#index"
end
如果我型耙路線我得到這個
rake routes
players GET /players(.:format) players#index
POST /players(.:format) players#create
new_player GET /players/new(.:format) players#new
edit_player GET /players/:id/edit(.:format) players#edit
player GET /players/:id(.:format) players#show
PUT /players/:id(.:format) players#update
DELETE /players/:id(.:format) players#destroy
root / players#index
index GET /index(.:format) players#index
我需要它,因爲我希望球員去剔掉,如果他們是在玩。所以在一場比賽之後,大多數玩家都會玩遊戲。然後,當下一場比賽到來時,它需要重置爲玩=假,以便他們可以說,如果他們正在玩或不玩。 – user1898829 2013-04-04 10:33:39