我在 Rails 应用程序中有一个包含邀请码和信用卡信息块的表单。我希望能够在同一页面上的两者之间切换。用户要么提供邀请码,要么输入信用卡信息。如果一个或另一个可以在不活动时隐藏(但不是必需的),那就太好了。这是表格的相关位:
%hr
%fieldset
.control-group
= label_tag :invite_code, nil, :class => "control-label"
.controls
= text_field_tag :invite_code
.control-group
.controls
= f.hidden_field :stripe_token
= f.hidden_field :last_4_digits
- if @user.last_4_digits
.control-group
= label_tag :card, nil, :class => "control-label"
.controls
Using card ending with #{@user.last_4_digits}
= link_to "(change)", "#"
%hr
%fieldset
%noscript
%p
This form requires Javascript to use
.control-group#credit-card{ :style => @user.last_4_digits ? "display:none" : "display:block" }
#credit-card-errors{:style => "display:none"}
#stripe-error-message.alert-message.block-message.error
.control-group
= label_tag :credit_card_number, nil, :class => "control-label"
.controls= text_field_tag :credit_card_number, params[:credit_card_number], :class => "field", :disabled => true
.control-group
= label_tag :cvv, "Security code (CVV)", :class => "control-label"
.controls= text_field_tag :cvv, params[:cvv], :class => "small", :disabled => true
.control-group
= label_tag :expiry_date, nil, :class => "control-label"
.controls= date_select "", :expiry_date, {:discard_day => true, :order => [:month, :year], :use_month_numbers => true, :start_year => Date.today.year, :end_year => Date.today.year + 25, :disabled => true}, {:class => "input-small"}
/empty
%p
Subscriptions will be billed $12 annually.
%fieldset.form-submit
= submit_tag 'Sign up', :class => 'btn btn-large btn-primary'
这样做最明智的方法是什么?