1

これを修正するには、config.rb に何を追加する必要がありますか。

私のレールに関する非常に限られた知識で、このメソッドをコントローラーに入れることができました。

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
4

3 に答える 3

1

できるよ:

ChooseTeams3::Application.routes.draw do
   resources :players do
     get "reset", on: :collection
   end
   root :to => "players#index"
   get   "/index" => "players#index"
end

ルーティングの詳細については、こちらのドキュメントを参照してください。

于 2013-04-04T09:14:54.783 に答える
0

ルート ファイルを次のように更新します。

ChooseTeams3::Application.routes.draw do
   resources :players do
     collection do
       get 'reset'
     end
  end
  root :to => "players#index"
  get   "/index" => "players#index"
end

このようにlink_toを使用します..

<p><%= link_to "New Game", reset_players_path%></p>
于 2013-04-04T09:30:00.963 に答える
0
ChooseTeams3::Application.routes.draw do
   resources :players do
     get "reset", on: :collection
   end
   root :to => "players#index"
   get   "/index" => "players#index"
end

<p><%= link_to "New Game", reset_players_path %></p>

def  reset
        Player.all.each do |p|
            p.update_attribute(:playing, false)
        end
end

それでも、「新しいゲーム」をクリックすると、ALL を false に更新する必要があります。

プレーヤー - モデルです。Player.all を呼び出すと、すべてのプレーヤーが更新されます。

game.playes.each (現在のゲームのすべてのプレイヤー) のようなものが必要かもしれません

于 2013-04-04T09:38:18.773 に答える