2016-04-10 12 views
0

私のレールアプリでは、この編集フォームが正しく動作していないようです。リンクを介して編集サイトに入ると、すべてがうまく見えますが、フォーム送信ボタンは機能しません。ウィンドウをリフレッシュするとうまく動作します。レールはリダイレクトされますが、更新ボタンは機能しません

Edit.html.erb

<div class="alien-choice"> 
     <h2 class="player_name"><%= current_user.username %></h2> 
     <p> Choose <span>0</span>/2 Power</p> 

    <%= form_for [@gameround, @currentplayer] do |f| %> 

     <% alleflares = @currentplayer.flares %> 

     <% alleflares.each { |val| 
      printAlien = Alien.find_by_title(val) 
     %> 
     <div class="alien_wrap"> 
      <h3><%= printAlien.title %> <span>[<%= printAlien.expansion.abbr %>]</span></h3> 

      <label for="<%= printAlien.title %>"> 
       <div class="alien" style="background-image: url(<%= printAlien.avatar.url %>)"> 
      </label> 

      <%= f.check_box(:aliens, { :multiple => true, :id => printAlien.title, :class => 'choosealiens'}, printAlien.title, nil) %> 

      </div> 
     </div> 


     <% } %> 

     </div> 
      <div class="actions"> 
      <%= f.submit %> 
     </div> 
    <% end %> 

<%= link_to 'Back', gameround_currentplayers_path %> 

コントローラあなたは次のように設定/ routes.rbをにあなたのルートを作成したい

class CurrentplayersController < ApplicationController 
    before_action :set_currentplayer, only: [:show, :edit, :update] 

    # GET /currentplayers 
    # GET /currentplayers.json 
    def index 
    @currentplayers = Currentplayer.all 
    end 

    # GET /currentplayers/1 
    # GET /currentplayers/1.json 
    def show 
    @gameround = Gameround.find(params[:gameround_id]) 
    @currentplayer = @gameround.currentplayers.find(params[:id]) 

    current_user 
    end 

    # GET /currentplayers/new 
    def new 
    @gameround = Gameround.find(params[:gameround_id]) 
    @currentplayer = Currentplayer.new 
    end 

    # GET /currentplayers/1/edit 
    def edit 
     @gameround = Gameround.find(params[:gameround_id]) 
     @currentplayer = @gameround.currentplayers.find(params[:id]) 

    end 

    # POST /currentplayers 
    # POST /currentplayers.json 
    def create 
    @gameround = Gameround.find(params[:gameround_id]) 

    @currentplayer = @gameround.currentplayers.create(currentplayer_params); 

    respond_to do |format| 
     if @currentplayer.save 
     format.html { redirect_to @gameround, notice: 'Currentplayer was successfully created.' } 
     format.json { render :show, status: :created, location: @currentplayer } 
     else 
     format.html { render :new } 
     format.json { render json: @currentplayer.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PATCH/PUT /currentplayers/1 
    # PATCH/PUT /currentplayers/1.json 
    def update 
     @gameround = Gameround.find(params[:gameround_id]) 
     @currentplayer = @gameround.currentplayers.find(params[:id]) 

     if @currentplayer.update(currentplayer_params) 
     redirect_to gameround_currentplayer_path 

     else 
     render 'edit' 
     end 


    end 

    # DELETE /currentplayers/1 
    # DELETE /currentplayers/1.json 
    def destroy 
    @gameround = Gameround.find(params[:gameround_id]) 
     @currentplayer = @gameround.currentplayers.find(params[:id]) 
    @currentplayer.destroy 
    respond_to do |format| 
     format.html { redirect_to '/play', notice: 'Currentplayer was successfully destroyed.' } 
     format.json { head :no_content } 
    end 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_currentplayer 
     @currentplayer = Currentplayer.find(params[:id]) 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
    def currentplayer_params 
     params.require(:currentplayer).permit(:log_id, :flares, :winner, :bases, :gameround_id, aliens:[]) 
    end 
end 

config.routes

Rails.application.routes.draw do 


    resources :gamerounds do 
    resources :currentplayers 
    end 

答えて

-1

resources :current_players 
+0

私は既にルートに追加しましたが、ネストされています。私はあなたのルートファイルを見ることができるように私の質問を更新しました。編集ページに入力してフォームを表示することはできますが、保存/更新ボタンをクリックすると何も起こりません。ただし、ページを更新すると、ボタンをクリックすると動作します。 – Candielope

0

私はそれを理解しました。サブミットボタンがメインディビジョンの外側にあるからです。ご迷惑おかけして申し訳ありません!

関連する問題