jQuery Datepicker在Heroku / Rails 3.1上不起作用 [英] jQuery Datepicker doesn't work on Heroku/Rails 3.1

查看:136
本文介绍了jQuery Datepicker在Heroku / Rails 3.1上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我对jQuery Datepicker和Rails 3.1非常沮丧。
它在我的开发环境中完美运行,但在Heroku / Cedar的生产环境中无法运行。它只是当我选择我的日期字段时不弹出。



所以这是我到目前为止所做的:

我把jquery文件转换为 \apps\assets\javascript


  • jquery-1.7.1.min.js

  • jquery-ui-1.8.17.custom.min.js

  • jquery.ui.datepicker-de.js



,并将它们添加到我的 production.rb 中:

 #预编译其他资源(application.js,application.css,以及所有非JS / CSS已添加)< br /> 
config.assets.precompile + =%w(event_calendar.js event_calendar.css jquery-1.7.1.min.js jquery-ui-1.8.17.custom.min.js jquery-ui-1.8.17。 custom.css jquery.ui.datepicker-de.js)

然后我在本地预编译我的资产正如这里所描述的,它们在 / public / assets / 和我的 manifest.yml 中。所以一切看起来都不错,我在推送我的应用程序到Heroku时没有遇到任何错误,但是当我选择与datepicker关联的文本字段时,没有任何反应,它根本不显示。



任何想法在这里可能是错误的吗?

如何找出问题所在?



在Heroku日志我只能找到这样的条目:


  cache:[GET /assets/application-58ec8ec4b5384a8fb8d7884169385e49.css]错过

如果有人可以提供帮助,会很开心。




更新:



这是我的 application.js

  // =要求jquery 
// =要求jquery_ujs
// =要求jquery -ui
// = require_tree。

$(document).ready(
function()
{
$(#picker)。datepicker($。datepicker.regional ['de' ]);
$(#picker)。datepicker();
}
);

据我所知 // = require_tree。负责在资产文件夹中包含所有JavaScript文件,例如 \app\assets\javascripts\ 。它是否包含 \public\assets ???中的预编译资产。



以下是我的 application.css

  / * 
*这是一个清单文件,它将自动包含此目录中可用的所有样式表
*和所有子目录。您可以自由地将应用程序范围的样式添加到该文件中,并且它们将出现在编译文件的顶部
*处,但通常最好为每个样式范围创建一个新文件。
* = require_self
* = require_tree。
* /
...

同样在这里,我认为 * = require_tree。负责 \app\assets\stylesheets 以及 \\ \\ public \assets ,我的预编译样式表。



这里指向heroku应用程序的链接,选择日期字段应该弹出,日历:

http:// smooth-window-1858 .herokuapp.com / events / new

解决方案

同时,我发现我的项目出了什么问题。
我必须在 \config\environments\production.rb 中禁用Rails的静态资产服务器:

  config.serve_static_assets = true 

我必须将 jquery-rails 添加到我的Gemfile中:

  gem' jquery-rails'

现在da tepicker工作正常,我从 / app / assets / javascript 中删除​​了jquery .js文件,因为gem负责处理这个问题。不过,我认为jquery文件是在资产预编译过程中添加的。



当我简单地在我的布局中引用Google CDN时,资产预编译(Heroku需要)如何工作,如:

 <%= stylesheet_link_taghttp://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/ jquery-ui.css,application%> 
<%= javascript_include_taghttp://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js,http://ajax.googleapis.com/ajax/ libs / jqueryui / 1.8.1 / jquery-ui.min.js,application%>


Hello everybody out there,

I'm very frustrated with the jQuery Datepicker and Rails 3.1. It runs perfectly in my develoment environment, but it doesn't work in the production environment on Heroku/Cedar. It simply doesn't pop-up when I select my date field.

So here's what I did so far:
I put the jquery files into \apps\assets\javascript:

  • jquery-1.7.1.min.js
  • jquery-ui-1.8.17.custom.min.js
  • jquery.ui.datepicker-de.js

and I added them among other files to my production.rb:

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) <br />
config.assets.precompile += %w( event_calendar.js event_calendar.css jquery-1.7.1.min.js jquery-ui-1.8.17.custom.min.js jquery-ui-1.8.17.custom.css jquery.ui.datepicker-de.js)

Then I precompiled my assets locally as described here and they appeared correctly in /public/assets/ and in my manifest.yml. So everything looks good and I don't get any errors while pushing my app to Heroku, but when I select my text field associated with the datepicker nothing happens, it simply doesn't show up.

Any ideas what could be wrong here?
How can I find out what the problem is?

In the Heroku Logs I can only find entries like this:

cache: [GET /assets/application-58ec8ec4b5384a8fb8d7884169385e49.css] miss

Would be happy if somebody could help, please.


Update:

Here's my application.js:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

$(document).ready(
  function()
  {
    $("#picker").datepicker($.datepicker.regional['de']);
    $("#picker").datepicker();
  }
);

As far as I know //= require_tree . takes care of including all javascript files in the assets folder, like \app\assets\javascripts\. Does that include precompiled assets in \public\assets ???.

And here's my application.css:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
*/
...

Same here, I thought *= require_tree . takes care of \app\assets\stylesheets as well as for \public\assets, where my precompiled stylesheets are.

Here the link to the app on heroku, selecting the date field should pop-up the calendar:
http://smooth-window-1858.herokuapp.com/events/new

解决方案

In the meantime I found out what's wrong with my project.
I had to disable Rails's static asset server in \config\environments\production.rb:

config.serve_static_assets = true

Overmore, I had to add jquery-rails to my Gemfile:

gem 'jquery-rails'

Now the datepicker works fine, and I removed the jquery .js files from /app/assets/javascript, because the gem takes care of that. However, I think jquery files are added in the process of asset precompilation. Where do they come from?

And how can asset precompilation (required by Heroku) work, when I simply refer the Google CDN in my layout, like:

  <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
  <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>

这篇关于jQuery Datepicker在Heroku / Rails 3.1上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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