1

我的应用程序中有一个错误,但我不知道去哪里找。当我使用 simple_form 格式重构我的表单时,例如:

<%= simple_form_for([@schedule.doctor, @schedule], :html => { :class => 'form-horizontal'}) do |f| %>

    <%= f.label :start_time %>
    <%= f.text_field :start_time %>
    <%= f.label :day %>
    <%= f.select :day, Date::DAYNAMES.zip((0..6).to_a) %>
    <%= f.label :is_available %>
    <%= f.check_box :is_available %>

    <%= f.submit %>
<% end %>

这是它生成的 HTML 代码(见粗体字)

<form id="new_schedule" class="simple_form form-horizontal" novalidate="novalidate" method="post" action="/doctors/1/schedules" accept-charset="UTF-8">
**<div style="margin:0;padding:0;display:inline">**
<label class="time optional control-label" for="schedule_start_time">Start time</label>
<input id="schedule_start_time" class="ui-timepicker-input" type="text" size="30" name="schedule[start_time]" autocomplete="off">
<label class="integer optional control-label" for="schedule_day">Day</label>
<select id="schedule_day" name="schedule[day]">
<label class="boolean optional control-label" for="schedule_is_available">Is available</label>
<input type="hidden" value="0" name="schedule[is_available]">
<input id="schedule_is_available" type="checkbox" value="1" name="schedule[is_available]">
<input type="submit" value="Create Schedule" name="commit">
</form>

知道什么可能导致这个问题吗?

我正在使用带有 simple_forms 的 bootstrap-sass

4

2 回答 2

0
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

  config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
        prepend.use :input
      end
      input.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
    end
  end

  config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.wrapper :tag => 'div', :class => 'input-append' do |append|
        append.use :input
      end
      input.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
    end
  end

  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap
end
于 2013-09-20T10:54:27.010 回答
0

解决方案:

我需要将它设置config.default_wrapper = :bootstrapsimple_form.rb文件中,并确保使用 simple_forms tags

于 2013-01-22T00:22:40.483 回答