0

こんにちは、Rails の入れ子になったフォームを使用しています。非常に単純なものが必要ですが、理由がわかりません。Rails の初心者です。

ネストされたフォームでは、ユーザーがリストのオプションを選択すると、スクリプトは自動的に 2 番目の選択リストを空白に挿入します。この空白は常にそこに残ります。

これを回避する方法はありますか..何も選択しない場合(もちろん選択のみ)、「新規追加」を押すまで、スクリプトはユーザーが別のオプションを追加するための新しい選択リストを追加します。

ありがとう..

コードを表示

<%= f.fields_for :citizens do |citizen_form| %>

    <div>
      <%= citizen_form.label  :citizen, t('generales.citizen')  %>
      <%= citizen_form.select :country_id , Country.all.collect {|p| [ t("generales."+p.iso), p.id ] }, { :include_blank => true } , { :class => 'pca33' } %>
      <div id="delerr"><%= citizen_form.link_to_remove t('generales.delete') %></div>
    </div>

  <% end %>

  <%= f.link_to_add t('generales.add'), :citizens %>

モデル Player.rb

class Player < ActiveRecord::Base

  belongs_to :user
  has_many   :clubs
  has_many   :links
  has_many   :references
  has_many   :achievements
  has_many   :citizens
  has_and_belongs_to_many :languages
  has_and_belongs_to_many :selections

  accepts_nested_attributes_for :clubs,        :allow_destroy => true, :reject_if => proc { |attributes| attributes['name'].blank? }
  accepts_nested_attributes_for :links,        :allow_destroy => true, :reject_if => proc { |attributes| attributes['url'].blank? }
  accepts_nested_attributes_for :references,   :allow_destroy => true, :reject_if => proc { |attributes| attributes['name'].blank? }
  accepts_nested_attributes_for :achievements, :allow_destroy => true, :reject_if => proc { |attributes| attributes['name'].blank? }
  accepts_nested_attributes_for :citizens,     :allow_destroy => true, :reject_if => proc { |attributes| attributes['country_id'].blank?}

  attr_accessible :name,
    :lastname,
    :birthday,
    :height,
    :height_measure,
    :weight,
    :weight_measure,
    :inches,
    :city,
    :birthplace,
    :other_languages,
    :cp,
    :phone,
    :cellphone,
    :web_page,
    :game_status,
    :club,
    :actual_club,
    :actual_country_club,
    :actual_division_club,
    :actual_contract_expiration_club,
    :last_club,
    :last_country_club,
    :last_division_club,
    :last_contract_expiration_club,
    :position,
    :alternative_position,
    :dominant_leg,

    #normal player
    :short_passes,
    :long_passes,
    :shots_half_distance,
    :shots_long_distance,
    :ball_habilities,
    :offensive_capability,
    :ball_driving,
    :defense_capability,
    :dribbling,
    :velocity,
    :vision_field,
    :movements_wothout_ball,
    :recovery_ball,
    :head_ball,
    :lidership,
    :teamwork,

    #goalkeeper
    :air_game,
    :clearance_technique, #técnica de despeje
    :ball_keep, #atajes
    :flexibility, #flexibilidad
    :penalty_keep, #atajar penales
    :achique,
    :defense_communication,
    :foot_game,
    :velocity_reaction, #reflejos
    :area_domination,
    :goalkeep_teamwork,
    :goalkeep_lidership,

    :strenghts,
    :weaknesses,

    :aditional_information,

    :active,

    :clubs_attributes,
    :links_attributes,
    :references_attributes,
    :achievements_attributes,
    :citizens_attributes,
    :avatar_file_name,
    :avatar_content_type,
    :avatar_file_size,
    :avatar,

    :language_ids,
    :selection_ids


    POSITIONS = %w{
      goalkeeper
      defense
      medium
      offensive
    }

    LEG = %w{
      left
      right
      both
    }

    # altura
    HEIGHT = (1..200).to_a

    INCH = (1..11).to_a

    # peso
    WEIGHT = (1..300).to_a

    HEIGHT_MEASURE = %w{
      cms
      pies
    }

    WEIGHT_MEASURE = %w{
      kgs
      lbs
    }


    Paperclip.interpolates :random_hex do |attachment, style|
    attachment.instance.random_hex
    end

    has_attached_file :avatar, :styles => { :profile => "300x300", :thumb => "100x100#"},
    :url  => "/assets/people/:id/:style/:hash.:extension",
    :path => ":rails_root/public/assets/people/:id/:style/:hash.:extension",
    :hash_secret => "longSecretString"

    validates_attachment_size         :avatar, :less_than    => 2.megabytes # Solo aceptar imágenes menores a 2 Mb.
    validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif']

    def defeated?
      t = Time.now - created_at

      mm, ss = t.divmod(60)
      hh, mm = mm.divmod(60)
      dd, hh = hh.divmod(24)

      dd > 180 ? true : false
    end
end

モデルの市民.rb

class Citizen < ActiveRecord::Base
  attr_accessible :country_id

  belongs_to :player


end
4

0 に答える 0