0

我在兩個Rails 3.2項目中使用SimpleForm和Twitter Bootstrap。不幸的是,我的表格在其中一個項目中沒有正確渲染。Twitter Bootstrap在兩個不同的Rails 3.2項目中呈現兩種不同的方式

所有相關的寶石都是相同的版本。

被正確地呈現有看起來像這樣的字段中的一個:

<form id="new_user" class="simple_form form-horizontal" novalidate="novalidate" method="post" action="/users" accept-charset="UTF-8" name="new_user"> 
    <div style="margin:0;padding:0;display:inline"> 
     <input type="hidden" value="✓" name="utf8"> <input type="hidden" value="I/WorRCjNpv7gnccGkL6/LETTgn6ao6Ycrgm0ky2slM=" name="authenticity_token"> 
    </div> 
    <div class="control-group string required"> 
     <label class="string required control-label" for="user_first_name"><abbr title="required">*</abbr> First name</label> 
     <div class="controls"> 
      <input id="user_first_name" class="string required" type="text" size="50" name="user[first_name]"> 
     </div> 
    </div> 
    <div class="control-group string required"> 
     <label class="string required control-label" for="user_last_name"><abbr title="required">*</abbr> Last name</label> 
     <div class="controls"> 
      <input id="user_last_name" class="string required" type="text" size="50" name="user[last_name]"> 
     </div> 
    </div> 
    <div class="control-group email required"> 
     <label class="email required control-label" for="user_email"><abbr title="required">*</abbr> Email</label> 
     <div class="controls"> 
      <input id="user_email" class="string email required" type="email" size="50" name="user[email]"> 
     </div> 
    </div> 
    <div class="control-group password required"> 
     <label class="password required control-label" for="user_password"><abbr title="required">*</abbr> Password</label> 
     <div class="controls"> 
      <input id="user_password" class="password required" type="password" size="50" name="user[password]"> 
     </div> 
    </div> 
    <div class="control-group password optional"> 
     <label class="password optional control-label" for="user_password_confirmation">Password confirmation</label> 
     <div class="controls"> 
      <input id="user_password_confirmation" class="password optional" type="password" size="50" name="user[password_confirmation]"> 
     </div> 
    </div> 
    <div class="control-group boolean optional"> 
     <label class="boolean optional control-label" for="user_admin">Admin</label> 
     <div class="controls"> 
      <input type="hidden" value="0" name="user[admin]"> <label class="checkbox"><input id="user_admin" class="boolean optional" type="checkbox" value="1" name="user[admin]"></label> 
     </div> 
    </div> 
    <div class="control-group string required"> 
     <label class="string required control-label" for="user_company"><abbr title="required">*</abbr> Company</label> 
     <div class="controls"> 
      <input id="user_company" class="string required" type="text" size="50" name="user[company]"> 
     </div> 
    </div> 
    <div class="form-actions"> 
     <input class="btn btn-primary" type="submit" value="Create User" name="commit"> <a class="btn" href="/users"><span class="translation_missing" title="translation missing: en.helpers.links.cancel">Cancel</span></a> 
    </div> 
</form> 

,而一個是不正確的獲取呈現這樣的:

<form id="new_user" class="simple_form form-horizontal" novalidate="novalidate" method="post" action="/users" accept-charset="UTF-8" name="new_user"> 
    <div style="margin:0;padding:0;display:inline"> 
     <input type="hidden" value="✓" name="utf8"> <input type="hidden" value="TR4q4W8cEl82hI6+bebVsoYp8WD3k2xsyhhf1UXzCYg=" name="authenticity_token"> 
    </div> 
    <div class="input string required"> 
     <label class="string required control-label" for="user_first_name"><abbr title="required">*</abbr> First name</label> <input id="user_first_name" class="string required" type="text" size="50" name="user[first_name]"> 
    </div> 
    <div class="input string required"> 
     <label class="string required control-label" for="user_last_name"><abbr title="required">*</abbr> Last name</label> <input id="user_last_name" class="string required" type="text" size="50" name="user[last_name]"> 
    </div> 
    <div class="input email required"> 
     <label class="email required control-label" for="user_email"><abbr title="required">*</abbr> Email</label> <input id="user_email" class="string email required" type="email" size="50" name="user[email]"> 
    </div> 
    <div class="input password required"> 
     <label class="password required control-label" for="user_password"><abbr title="required">*</abbr> Password</label> <input id="user_password" class="password required" type="password" size="50" name="user[password]"> 
    </div> 
    <div class="input password optional"> 
     <label class="password optional control-label" for="user_password_confirmation">Password confirmation</label> <input id="user_password_confirmation" class="password optional" type="password" size="50" name="user[password_confirmation]"> 
    </div> 
    <div class="input boolean optional"> 
     <input type="hidden" value="0" name="user[admin]"> <label class="boolean optional control-label checkbox" for="user_admin"><input id="user_admin" class="boolean optional" type="checkbox" value="1" name="user[admin]"> Admin</label> 
    </div> 
    <div class="form-actions"> 
     <input class="btn btn-primary" type="submit" value="Create User" name="commit"> <a class="btn" href="/users"><span class="translation_missing" title="translation missing: en.helpers.links.cancel">Cancel</span></a> 
    </div> 
</form> 

我按照相同的步驟(據我所知)在這兩個項目上。爲什麼Twitter Bootstrap導致兩者渲染不同?或者它是SimpleForm?

+0

這很可能是SimpleForm。你能發佈一切,包括'

'嗎? – Zepplock

回答

0

我發現了這個問題,但我仍然不確定它爲什麼發生。這確實是一個SimpleForm問題,而不是Twitter Bootstrap問題。

config/initializers/simple_form.rb文件在兩者之間產生不同。我不知道爲什麼。

我在MiniTest引發的安裝過程中遇到了一些錯誤。

0

看起來問題是簡單的形式。

Twitter Bootstrap只處理樣式,SimpleForm生成html。

您確定,您在兩個項目上都使用相同版本的SimpleForm嗎?或者,也許你忘了在後面的那個電話上調用simple_form_for。

編輯:

安裝後,你是否運行twitter bootstrap生成器?

rails generate simple_form:install --bootstrap 
相關問題