我正在尝试让一个简单的 jquery datepicker 工作。我已经关注了 railscasts 的情节,甚至能够下载并让他的版本正常工作。我不确定为什么它不适用于我的项目。但是当我在里面点击时,没有任何动作,也没有弹出日期选择器。
控制台显示以下错误:
TypeError: $(...).datepicker is not a function
[Break On This Error]
dateFormat: 'yy-mm-dd'
更多控制台测试产生:
Object[input#datemodel_dated]
>>> $('#datemodel_dated').datepicker
undefined
>>> $('#datemodel_dated').datepicker()
TypeError: $(...).datepicker is not a function
[Break On This Error]
$('#datemodel_dated').datepicker()
erb代码:
<div class="field">
<%= f.label :dated %><br />
<%= f.text_field :dated %>
</div>
从萤火虫中提取的代码:
(function() {
jQuery(function() {
return $('#datemodel_dated').datepicker({
dateFormat: 'yy-mm-dd'
});
});
}).call(this);
咖啡脚本代码:
jQuery ->
$('#datemodel_dated').datepicker
dateFormat: 'yy-mm-dd'
宝石文件
group :assets do
# ...
gem 'jquery-ui-rails'
end
应用程序/资产/javascripts/application.js
//= require jquery.ui.datepicker
应用程序/资产/样式表/application.css
*= require jquery.ui.datepicker
这是生成的 HTML
<!DOCTYPE html>
<html>
<head>
<title>Realestate</title>
<meta name="description" content="...">
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
<link href="/assets/jquery.ui.core.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/jquery.ui.theme.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/jquery.ui.datepicker.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/normalize.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/defaults.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/forms.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/blogs.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/borrowers.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/buyers.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/contacts.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/lenders.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/prospective_properties.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/sellers.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.core.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.datepicker.js?body=1" type="text/javascript"></script>
<script src="/assets/datemodels.js?body=1" type="text/javascript"></script>
<script src="/assets/account_members.js?body=1" type="text/javascript"></script>
<script src="/assets/accounts.js?body=1" type="text/javascript"></script>
<script src="/assets/blogs.js?body=1" type="text/javascript"></script>
<script src="/assets/borrowers.js?body=1" type="text/javascript"></script>
<script src="/assets/buyers.js?body=1" type="text/javascript"></script>
<script src="/assets/companies.js?body=1" type="text/javascript"></script>
<script src="/assets/contacts.js?body=1" type="text/javascript"></script>
<script src="/assets/customers.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/journal_entries.js?body=1" type="text/javascript"></script>
<script src="/assets/journals.js?body=1" type="text/javascript"></script>
<script src="/assets/labels.js?body=1" type="text/javascript"></script>
<script src="/assets/leases.js?body=1" type="text/javascript"></script>
<script src="/assets/lenders.js?body=1" type="text/javascript"></script>
<script src="/assets/pages.js?body=1" type="text/javascript"></script>
<script src="/assets/properties.js?body=1" type="text/javascript"></script>
<script src="/assets/prospective_properties.js?body=1" type="text/javascript"></script>
<script src="/assets/rent_logs.js?body=1" type="text/javascript"></script>
<script src="/assets/rental_units.js?body=1" type="text/javascript"></script>
<script src="/assets/roles.js?body=1" type="text/javascript"></script>
<script src="/assets/sellers.js?body=1" type="text/javascript"></script>
<script src="/assets/users.js?body=1" type="text/javascript"></script>
<script src="/assets/vendors.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="2kpUpKPNVpHhk9UfDo1CutyVebDLvkwQXUe86qkmIPM=" name="csrf-token" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29109749-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="contents">
<div class="header">
<div class="menu">
...
</div>
<div class="section">
<div class="column1">
<img alt="Mini_lion_logo" src="/assets/mini_lion_logo.png" width="100px" />
</div>
<div class="left column2">
<div class = "row">
<form action="/sellers/new" class="button_to" method="get"><div><input type="submit" value="Sell" /></div></form>
...
</div>
<div class = "hide">
<div class="row">
<form action="/buyers/new" class="button_to" method="get"><div><input type="submit" value="Buy/Rent" /></div></form>
...
</div>
</div>
</div>
</div>
</div>
<div class="section">
<p class="notice"></p>
<h1>New datemodel</h1>
<form accept-charset="UTF-8" action="/datemodels" class="new_datemodel" id="new_datemodel" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="2kpUpKPNVpHhk9UfDo1CutyVebDLvkwQXUe86qkmIPM=" /></div>
<div class="field">
<label for="datemodel_dated">Dated</label><br />
<input id="datemodel_dated" name="datemodel[dated]" size="30" type="text" />
</div>
<div class="actions">
<input name="commit" type="submit" value="Create Datemodel" />
</div>
</form>
</div>
</div>
</body>
</html>
为了更好地衡量,我在开发日志中没有看到任何问题,但我可能不知道要寻找什么:
Started GET "/pm/leases/2/edit" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Processing by Pm::LeasesController#edit as HTML
Parameters: {"id"=>"2"}
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Lease Load (0.4ms) SELECT `leases`.* FROM `leases` WHERE `leases`.`id` = 2 LIMIT 1
RentalUnit Load (0.4ms) SELECT `rental_units`.* FROM `rental_units` WHERE `rental_units`.`id` = 1 LIMIT 1
Property Load (0.3ms) SELECT `properties`.* FROM `properties` WHERE `properties`.`id` = 1 LIMIT 1
Rendered pm/leases/_lease_form.html.erb (142.2ms)
Rendered pm/leases/_form.html.erb (160.7ms)
Rendered pm/leases/edit.html.erb within layouts/application (163.2ms)
Rendered layouts/_analytics.html.erb (0.0ms)
Rendered layouts/_home_header.html.erb (3.8ms)
Rendered layouts/_home_footer.html.erb (0.0ms)
Completed 200 OK in 490ms (Views: 205.0ms | ActiveRecord: 9.0ms)
Started GET "/assets/datemodels.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /datemodels.js - 200 OK (0ms)
Started GET "/assets/jquery.ui.theme.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /jquery.ui.theme.css - 304 Not Modified (2ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/home.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /home.css - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/lenders.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /lenders.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.ui.core.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /jquery.ui.core.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.ui.datepicker.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /jquery.ui.datepicker.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/account_members.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /account_members.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/accounts.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /accounts.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/borrowers.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /borrowers.js - 304 Not Modified (0ms)
Started GET "/assets/buyers.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /buyers.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/companies.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /companies.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/contacts.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /contacts.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/blogs.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /blogs.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/home.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /home.js - 304 Not Modified (0ms)
[2013-03-14 18:17:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/customers.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:45 +0200
Served asset /customers.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/journal_entries.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /journal_entries.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/journals.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /journals.js - 304 Not Modified (1ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/labels.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /labels.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/leases.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /leases.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/lenders.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /lenders.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/properties.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /properties.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/pages.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /pages.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/prospective_properties.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /prospective_properties.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/rent_logs.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /rent_logs.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/rental_units.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /rental_units.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/sellers.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /sellers.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/roles.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /roles.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /users.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/vendors.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /vendors.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.ui.core.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /jquery.ui.core.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.ui.datepicker.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /jquery.ui.datepicker.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/borrowers.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /borrowers.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/buyers.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /buyers.css - 304 Not Modified (0ms)
Started GET "/assets/contacts.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /contacts.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/prospective_properties.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /prospective_properties.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/blogs.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /blogs.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/forms.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /forms.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/sellers.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /sellers.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/normalize.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /normalize.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/defaults.css?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /defaults.css - 304 Not Modified (0ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-03-14 18:17:46 +0200
Served asset /jquery.js - 304 Not Modified (1ms)
[2013-03-14 18:17:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
我已经阅读了这里的所有其他文章,但找不到解决方案。我确定这很简单...
我正在使用 Rails 3.2.12、Ruby 1.9.3