Padrino管理员屏幕

时间:2014-11-24 13:59:56

标签: haml padrino

我正在使用Padrino管理屏幕,并希望在编辑视图中使用haml显示下拉列表。在列表视图中,我想显示国家名称而不是它显示的ID号是否可能?我是haml的新手。

我正在使用国家和州

_form.haml

<code>
- error = @province.errors.include?(:countries_id)
%fieldset.control-group{:class => error ? 'has-error' : ''}
  =f.label :countries_id, :class => 'control-label'
  .controls
    =f.select(:countries_id, :collection => @cntrylist, :fields => [:country_name, :id], :selected => :id, :include_blank => false , :class => :dropdown, :prompt => "Select Province/State")
    %span.help-inline=error ? f.error_message_on(:countries_id, :class => 'dropdown-error') : pat(:example)
- error = @province.errors.include?(:province_name)
%fieldset.control-group{:class => error ? 'has-error' : ''}
  =f.label :province_name, :class => 'control-label'
  .controls
    =f.text_field :province_name, :class => 'form-control input-large input-with-feedback'
    %span.help-inline=error ? f.error_message_on(:province_name, :class => 'text-error') : pat(:example)
- error = @province.errors.include?(:province_code)
%fieldset.control-group{:class => error ? 'has-error' : ''}
  =f.label :province_code, :class => 'control-label'
  .controls
    =f.text_field :province_code, :class => 'form-control input-large input-with-feedback'
    %span.help-inline=error ? f.error_message_on(:province_code, :class => 'text-error') : pat(:example)

.form-actions
  =f.submit pat(:save), :class => 'btn btn-primary'
  &nbsp;
  =f.submit pat(:save_and_continue), :class => 'btn btn-info', :name => 'save_and_continue'
  &nbsp;
  =link_to pat(:cancel), url(:provinces, :index), :class => 'btn btn-default'
 </code>

This works as expected for new but for edit I would prefer to display the dropdown rather than id which it shows

index.haml

%tbody
          -@provinces.each do |province|
            %tr.list-row
              %td.list-column.list-selectable
                  =check_box_tag 'province_ids[]', :value => province.id, :class => 'list-selectable-checkbox'
              %td.list-column=province.id
             %td.list-column=province.countries_id

%tbody -@provinces.each do |province| %tr.list-row %td.list-column.list-selectable =check_box_tag 'province_ids[]', :value => province.id, :class => 'list-selectable-checkbox' %td.list-column=province.id %td.list-column=province.countries_id 在显示countries_id的td.list列中,我希望将其作为country_name。

由于

0 个答案:

没有答案