2010-10-20 80 views
1

我一直試圖在註冊期間創建一個用戶的出生日期選擇字段。 的代碼看起來是這樣的:使用calendar_date_select與Rails 3

<div id="content"> 
<h3>Register</h3> 
    <%= form_for(@user) do |f| %> 
    <div style="width: 374px; margin: 0 auto;"> 
     <%= f.label :name %> 
     <%= f.text_field :name %> 
     <div style="clear: both;"></div> 
     <%= f.label :email %> 
     <%= f.text_field :email %> 
     <div style="clear: both;"></div> 
     <%= f.label :dob %> 
     <%= f.calendar_date_select "e_date" %> 
    </div> 
    <% end %> 
</div> 

當我嘗試加載它,鐵軌給我這個錯誤:

undefined method `calendar_date_select' for #<#<Class:0x00000101210208>:0x0000010120d0a8> 

我在做什麼錯?

編輯我使用安裝在calendar_date_select寶石:寶石 安裝calendar_date_select 我運行OS X Snow Leopard的,如果它很重要。

+2

是否安裝了calendar_date_select寶石? – 2010-10-20 16:19:23

回答

9
  1. 加入Gemfile中:
    gem 'calendar_date_select', :git => 'git://github.com/paneq/calendar_date_select.git'

    不要使用rails3test分支它是舊的,被previously合併到主

  2. 運行bundle install

  3. 運行rake calendar:install
  4. 添加<%= calendar_date_select_includes %> AFTER <%= javascript_include_tag :defaults%> i n您的佈局
  5. 添加<%= f.calendar_date_select "calendar" %>到您的視圖
+0

好的工作..... – Straff 2012-02-28 09:50:38

+1

不應該使用bundle exec運行所有的可執行文件(如rake)嗎? http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/ – 2012-06-05 07:22:12

+0

這樣做後,你應該重新啓動服務器。至少我完成了上面的說明後就能像這樣工作。 – marimaf 2012-06-11 05:45:20