0

팀이 토너먼트에 등록 할 수있는 양식이 있습니다. 양식을 저장하면 처음에 양식을 저장할 때 & 경로가 예상대로 저장됩니다. 그러나 root_path & 팀으로 등록하는 과정을 반복하면 양식이 전혀 저장되지 않습니다 ("제출"단추를 클릭해도 아무 것도하지 않습니다).레일이 깊이 중첩 됨 form_for를 두 번 저장하지 못함

내 감정은 새로운 것을 멈추고있는 원본 저장 장치에 뭔가가 걸려 있지만 내 손가락을 그대로 둘 수는 없다는 느낌입니다. 아래 코드는 충분하다고 생각합니다.

(routes.rb)

root 'tournaments#index' 
    resources :tournaments do 
    resources :teams do 
     resources :players, :only => [:new, :create] 
    end 
    end 

(모델)

class Tournament < ApplicationRecord 
    has_many :teams 
    has_many :players, :through => :teams 

    accepts_nested_attributes_for :teams 
    accepts_nested_attributes_for :players 
end 

class Team < ApplicationRecord 
    belongs_to :tournament, required: false 
    has_many :players 

    accepts_nested_attributes_for :players 
end 

class Player < ApplicationRecord 
    belongs_to :team, required: false 
    has_one :tournament, :through => :team 
end 

(tournaments_controller.rb)

def index 
    @tournaments = Tournament.all 
    end 

    def show 
    @tournament = Tournament.find(params[:id]) 
    end 

    def new 
    @tournament = Tournament.new 
    end 

    def create 
     @tournament = Tournament.new(tournament_params) 
     if @tournament.save 
     flash[:notice] = "#{@tournament.name} saved." 
     redirect_to root_path 
    else 
     render :new 
    end 
    end 


    private 

    def tournament_params 
    params.require(:tournament).permit(:name, :deadline, :divisions, :info, :payment, :tournament_date, team_attributes: [:name, :division, :contact_email, :contact_name]) 
    end 

(teams_controller.rb)

def create 
     @team = Team.new(team_params) 
     if @team.save 
      flash[:notice] = "Team Registered." 
      redirect_to tournament_team_path(params[:tournament_id], @team.id) 
     else 
      redirect_to new_tournament_team_path(params[:tournament_id]) 
     end  
    end 

    def new 
     @tournament = Tournament.find_by_id(params[:tournament_id]) 
     @team = Team.new 
     8.times do 
      @team.players.build 
     end 
    end 

    def show 
    @tournament = Tournament.find(params[:tournament_id]) 
    @team = Team.find(params[:id]) 
    end 


    private 

    def team_params 
    params.require(:team).permit(:name, :tournament_id, :division, :contact_name, :contact_email, players_attributes: [ :name, :gender, :referee ]) 
    end 
팀에 대회 번호 쇼 페이지에서 617,451,515,

항목 링크 # 새로운 액션 (이 ... 작동까지 올바른 페이지로 연결하는 것과 같은)

<%= link_to(new_tournament_team_path(params[:id])) do %><div class="rounded_btn"><h3>Register Team</h3></div><% end %> 

(팀/new.html.erb) -이 작동하지 않는 양식입니다. 나는 partials를 사용해야한다. 그러나 나는 그것이 작동하기 시작하도록하고 싶다.

<body> 
    <container> 
     <header class="header" id="header"> 
    <a href="/"><img alt="Taipei Touch Association Logo" src="/assets/taipei_touch_logo_faded-4bbdd185e462f4d8af3b2d25f221f27f4ae479c8adfa4701b8c3f03e9e31b36c.svg"></a> 
    <span class="header_span"> 
     <h4>Taipei Touch Association</h4> 
     <h3>Tournament Management System</h3> 
    </span> 
</header> 
    <main class="long_page"> 
    <h1 class="tournament_name">Dummy Tournament</h1> 
    <h3 class="tournament_name">Team Registration</h3> 
<section style="align-items: baseline;"> 
    <div class="rounded_box"> 
     <form class="new_team" id="new_team" action="/tournaments/1/teams" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="+CtsL2QcMjj1703iGPpwgs8vYu7TWJfWt9jTUgCYTMaFE9JdvYIMJqdb87z4vKuDzUgb8RO96Mdvk5fW/uJUSw=="> 
     <input value="1" type="hidden" name="team[tournament_id]" id="team_tournament_id"> 
      <div> 
      <p> 
       <label for="team_division">Division: </label> 
       <select name="team[division]" id="team_division"><option value="mixed">Mixed</option> 
<option value="mens">Mens</option></select> 
      </p> 
      <p> 
       <input required="required" type="text" name="team[name]" id="team_name"> 
       <label alt="Team Name" placeholder="Team Name"></label> 
      </p> 
      <p> 
       <input required="required" type="text" name="team[contact_name]" id="team_contact_name"> 
       <label alt="Contact Person" placeholder="Contact Person"></label> 
      </p> 
      <p> 
       <input required="required" type="text" name="team[contact_email]" id="team_contact_email"> 
       <label alt="Contact Email" placeholder="Contact Email"></label> 
      </p> 
      <div class="clear"></div> 
      </div> 


       <div> 
        <input required="required" type="text" name="team[players_attributes][0][name]" id="team_players_attributes_0_name"> 
        <select name="team[players_attributes][0][gender]" id="team_players_attributes_0_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][0][referee]" id="team_players_attributes_0_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][1][name]" id="team_players_attributes_1_name"> 
        <select name="team[players_attributes][1][gender]" id="team_players_attributes_1_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][1][referee]" id="team_players_attributes_1_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][2][name]" id="team_players_attributes_2_name"> 
        <select name="team[players_attributes][2][gender]" id="team_players_attributes_2_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][2][referee]" id="team_players_attributes_2_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][3][name]" id="team_players_attributes_3_name"> 
        <select name="team[players_attributes][3][gender]" id="team_players_attributes_3_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][3][referee]" id="team_players_attributes_3_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][4][name]" id="team_players_attributes_4_name"> 
        <select name="team[players_attributes][4][gender]" id="team_players_attributes_4_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][4][referee]" id="team_players_attributes_4_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][5][name]" id="team_players_attributes_5_name"> 
        <select name="team[players_attributes][5][gender]" id="team_players_attributes_5_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][5][referee]" id="team_players_attributes_5_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][6][name]" id="team_players_attributes_6_name"> 
        <select name="team[players_attributes][6][gender]" id="team_players_attributes_6_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][6][referee]" id="team_players_attributes_6_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

       <div> 
        <input required="required" type="text" name="team[players_attributes][7][name]" id="team_players_attributes_7_name"> 
        <select name="team[players_attributes][7][gender]" id="team_players_attributes_7_gender"><option value="male">Male</option> 
<option value="female">Female</option></select> 
        <select name="team[players_attributes][7][referee]" id="team_players_attributes_7_referee"><option value="no">No</option> 
<option value="yes">Yes</option></select> 

       </div> 

      </form></div> 
      <div class="btn_holder"> 
      <p> 
    <input type="submit" name="commit" value="Submit Team" class="rounded_btn" data-disable-with="Submit Team"> 
</p></div> 

</section> 
    </main> 
    </container> 




</body> 

참고 :

<main class="long_page"> 
    <h1 class="tournament_name"><%= @tournament.name %></h1> 
    <h3 class="tournament_name">Team Registration</h3> 
<section style="align-items: baseline;"> 
    <div class="rounded_box"> 
     <%= form_for [@tournament, @team] do |f| %> 
     <%= f.hidden_field :tournament_id, :value => @tournament.id %> 
      <div> 
      <p> 
       <%= f.label :division, "Division: " %> 
       <%= f.select :division, options_for_select([["Mixed", "mixed"], ["Mens", "mens"]]) %> 
      </p> 
      <p> 
       <%= f.text_field :name, required: '' %> 
       <label alt='Team Name' placeholder='Team Name'></label> 
      </p> 
      <p> 
       <%= f.text_field :contact_name, required: '' %> 
       <label alt='Contact Person' placeholder='Contact Person'></label> 
      </p> 
      <p> 
       <%= f.text_field :contact_email, required: '' %> 
       <label alt='Contact Email' placeholder='Contact Email'></label> 
      </p> 
      <div class="clear"></div> 
      </div> 

      <%= f.fields_for :players do |builder| %> 
       <div> 
        <%= builder.text_field :name, required: '' %> 
        <%= builder.select :gender, options_for_select([["Male", "male"], ["Female", "female"]]) %> 
        <%= builder.select :referee, options_for_select([["No", "no"], ["Yes", "yes"]]) %> 

       </div> 
      <% end %> 

      </div> 
      <div class="btn_holder"> 
      <p> 
    <%= f.submit 'Submit Team', :class => 'rounded_btn' %> 
</p></div> 
     <% end %> 
    </div> 
</section> 

이것은 다음과 같은 HTML 출력을 생성하는 nested_forms 보석을 사용하는 경우이 문제도 지속됩니다.

+0

AJAX 양식 (그렇지 않은 경우)이 제출 단추를 멈추게 할 수있는 유일한 방법은 HTML 구문 오류입니다. 페이지로 돌아가서 제대로 작동하지 않으면 마우스 오른쪽 버튼을 클릭하고 제출 버튼 요소를 검사 한 다음 요소 코드와 3 개의 부모 중 2 개를 붙여 넣습니다. – RichardAE

+0

@RichardAE 제출 버튼과

코드 주위의 코드는 입니다. ' '
\t

\t

' – afishintaiwan

+0

질문과 HTML 코드를 편집하여 제대로 포맷 할 수 있습니까? – RichardAE

답변

0

내 /views/application.erb.html 파일 &에서 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>을 삭제했습니다. 이제는 효과가있는 것처럼 보입니다.