控制器合并

时间:2016-08-22 23:09:08

标签: ruby-on-rails ruby-on-rails-4

我有一个PokemonBattles控制器,我有方法创建,新的和更新。一切都很好用新的但没有更新。我尝试访问编辑视图时收到的错误。

undefined method `pokemon_battle_path' for 
#<#<Class:0x007f692e7251c0>:0x007f692e7202d8>

Did you mean?  pokemon_battles_path

控制器/ pokemon_battles_controller.rb

def create
    pokemon_a = Pokemon.find(params[:pokemon_battle][:pokemon_a_id])
    @pokemon_battle = PokemonBattle.create(pokemon_a_id: pokemon_a.id, 
        match_status: :upcoming, 
        pokemon_a_hp: pokemon_a.base_experience, 
        user_a_id: current_user.id)
    redirect_to arena_index_path
end

def new
    user = User.find(current_user.id)
    @pokemons = user.pokemons

    @pokemon_battle = PokemonBattle.new
end

def edit
    @pokemon_battle = PokemonBattle.find(params[:id])
end

配置/ routes.rb中

resources :pokemon_battles, only: [:new, :create, :edit]

视图/ pokemon_battles / edit.html.slim

section
    = form_for @pokemon_battle do |f|
        - @pokemons.each do |pokemon|
            = f.radio_button :pokemon_b_id, pokemon.id 
            = f.label "pokemon_b_id_#{pokemon.id}", pokemon.name
            = f.submit 'Choose', class: 'btn btn-primary'

0 个答案:

没有答案