在 Rails 3 中使用 calendar_date_select [英] Using calendar_date_select with Rails 3

查看:43
本文介绍了在 Rails 3 中使用 calendar_date_select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在注册期间创建用户出生日期选择字段.代码如下所示:

<h3>注册</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" %>

<%结束%>

当我尝试加载它时,rails 给了我这个错误:

未定义的方法`calendar_date_select' for #<#:0x0000010120d0a8>

我做错了什么?

EDIT 我使用以下方法安装了 calendar_date_select gem:gem install calendar_date_select如果重要的话,我正在运行 OS X Snow Leopard.

解决方案

  1. 添加到 Gemfile:
    gem 'calendar_date_select', :git =>'git://github.com/paneq/calendar_date_select.git'

    不要使用 rails3test 分支,它很旧并且之前合并到 master

  2. 运行捆绑安装

  3. 运行 rake calendar:install
  4. 在您的布局中添加 <%= calendar_date_select_includes %> AFTER <%= javascript_include_tag :defaults%>
  5. <%= f.calendar_date_select "calendar" %> 添加到您的视图中

I've been trying to create a user date-of-birth selection field during sign up. The code looks like this:

<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>

When I try to load it, rails gives me this error:

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

What am I doing wrong?

EDIT I installed the calendar_date_select gem using: gem install calendar_date_select I'm running OS X Snow Leopard if it matters.

解决方案

  1. Add to Gemfile:
    gem 'calendar_date_select', :git => 'git://github.com/paneq/calendar_date_select.git'

    Don't use the rails3test branch it is old and was previously merged into master

  2. run bundle install

  3. run rake calendar:install
  4. Add <%= calendar_date_select_includes %> AFTER <%= javascript_include_tag :defaults%> in your layout
  5. Add <%= f.calendar_date_select "calendar" %> to your view

这篇关于在 Rails 3 中使用 calendar_date_select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆