2014-12-23 50 views
0

我在編輯用戶的個人資料頁面中的生日字段如圖所示,需要內嵌的日期,月份和年份選擇標籤

enter image description here

我希望以這種方式來顯示,水平

enter image description here

到目前爲止,我使用下面的代碼,

在參觀者/ edit.html.erb,

<%= simple_form_for([@user],:url => visitor_path(@user), method: :put, :class => 'form form-horizontal') do |f| %> 
    <%= f.label :birthday %>  
    <div class="form-group"> 
    <div class="col-sm-2"> 
     <%= birthday_field_for(f, end_year: Date.today.year) %> 
    </div> 
    </div> 
<% end %> 

在application_helper.rb,

def birthday_field_for(form,options={}) 
    date_field_for(form,:birthday,options.reverse_merge!(start_year: Date.today.year - 90, end_year: Date.today.year - 13)) 
end 

def date_field_for(form,field,options={}) 
    form.date_select(field, options.reverse_merge!(order: [:day, :month, :year], 
               include_blank: true)) 
end 

請幫助我的CSS。

+0

u能張貼HTML和CSS u've – Aru

+1

你的小提琴是容器可能太小。簡單形式日期輸入自然內聯 – jmore009

+0

@Aru請檢查http://jsfiddle.net/cofa5hx8/。這裏有點好了。但不是在我的應用程序。 –

回答

0

感謝您的回答!

選擇容器寬度設置爲100%。因此,下一個選擇標籤出現在新行中。

添加訪客/ edit.html.erb一個css,沒有解決我的問題,

<% content_for :head_css do %> 
    <style type="text/css"> 
    .select2-container { 
     width: 120px !important; 
    } 
    </style> 
<% end %>