嗨,我正在使用 Rails 嵌套表单,我需要一些非常简单的东西,但我不知道为什么,因为我是 Rails 中的菜鸟。
在嵌套表单中,当用户在列表中选择一个选项时,脚本会自动插入第二个选择列表,在空白处,此空白始终存在,
有没有办法避免这种情况..所以如果你什么都没选择,(只是选择当然),直到你点击“添加新”,然后脚本添加一个新的选择列表供用户添加另一个选项。
谢谢..
查看代码
<%= 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 %>
模型播放器.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