Rails/facebox_render-未定义Ajax(facebox始终处于加载状态...) [英] Rails/facebox_render - Ajax is not defined (facebox's always loading...)

查看:111
本文介绍了Rails/facebox_render-未定义Ajax(facebox始终处于加载状态...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用facebox_render和rails 3做一个简单的测试.

这是我的步骤:

1.)已安装Jquery 1.4.2(Jrails)

2.)安装了插件 Rails插件安装git://github.com/ihower/facebox_render.git

3.),并添加了以下几行:

在我的application.html.erb

<head>
  <title><%= yield(:title) || "Untitled" %></title>
  <%= stylesheet_link_tag "reset", "application", "facebox" %>
  <%= javascript_include_tag :defaults, "facebox" %>
  <%= csrf_meta_tag %>
  <%= yield(:head) %>
</head>

以及在我的application_controller

class ApplicationController < ActionController::Base
  include FaceboxRender
end

当我尝试在面板中加载某些东西时,我只有加载器,什么也没出现...

例如,在我的home/index.html.erb

<%= facebox_link_to "test", :url => "/images/rails.png" %> 

在文档中,我很高兴知道我错了:

* facebox_link_to helper, it’s will launch loading facebox first, send ajax request second)
* link_to :remote => true, form_for :remote => true …etc Ajax helper (for Rails 3)

所以我认为我一直无法发送ajax请求.

在查看以下帖子后: >

但是我的js文件已正确加载:(如源代码所示)

<link href="/stylesheets/reset.css" media="screen" rel="stylesheet" type="text/css">
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css">
<link href="/stylesheets/facebox.css" media="screen" rel="stylesheet" type="text/css">
<script src="/javascripts/jquery.min.js" type="text/javascript"></script>
<script src="/javascripts/rails.js" type="text/javascript"></script>
<script src="/javascripts/facebox.js" type="text/javascript"></script>
<script src="/javascripts/application.js" type="text/javascript"></script>

感谢您的帮助!

我所做的是先安装facebox_render,然后再安装jRails.如果要重新安装,则可能要添加--force.

确保您拥有最新的jQuery.首先包含jQuery,然后包含facebox.js 另外,我始终确保先将facebox.css链接到其他样式之前,否则它可能会覆盖您的某些样式.并通过查看源代码验证js和CSS链接是否正常工作.

此外,请验证以下行:

<%= facebox_link_to "Sign Up&nbsp;", :url => new_account_path, :method => :get %>

我添加了:method =>:get以确保它创建了:

<a onclick="jQuery.facebox(function(){ jQuery.ajax({data:'authenticity_token=' + encodeURIComponent('Jbge/CYS4eXQ1d21E/S7tEcTm3dGdStdCtX9MwDx98o='), dataType:'script', type:'get', url:'/account/new'}) }); return false;" href="#">Sign Up&nbsp;</a>

I tried to make a simple test with facebox_render and rails 3.

Here are my steps:

1.) Installed Jquery 1.4.2 (Jrails)

2.) Installed the plugin rails plugin install git://github.com/ihower/facebox_render.git

3.) and added the following lines:

in my application.html.erb

<head>
  <title><%= yield(:title) || "Untitled" %></title>
  <%= stylesheet_link_tag "reset", "application", "facebox" %>
  <%= javascript_include_tag :defaults, "facebox" %>
  <%= csrf_meta_tag %>
  <%= yield(:head) %>
</head>

and in my application_controller

class ApplicationController < ActionController::Base
  include FaceboxRender
end

When I tried to load something in the facebox, I have only the loader, nothing appears...

for example, in my home/index.html.erb

<%= facebox_link_to "test", :url => "/images/rails.png" %> 

I would be pleased to know where I am wrong, In the doc:

* facebox_link_to helper, it’s will launch loading facebox first, send ajax request second)
* link_to :remote => true, form_for :remote => true …etc Ajax helper (for Rails 3)

So I think I'm stuck to send ajax request..

After looking the following post: How to make facebox popup remain open and the content inside the facebox changes after the submit it seems that I have the same problem: I can see "Ajax is not defined" in yhe firebug console

My js files is however correctly loaded: (as the source code shows)

<link href="/stylesheets/reset.css" media="screen" rel="stylesheet" type="text/css">
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css">
<link href="/stylesheets/facebox.css" media="screen" rel="stylesheet" type="text/css">
<script src="/javascripts/jquery.min.js" type="text/javascript"></script>
<script src="/javascripts/rails.js" type="text/javascript"></script>
<script src="/javascripts/facebox.js" type="text/javascript"></script>
<script src="/javascripts/application.js" type="text/javascript"></script>

Thanks for any help!

解决方案

what i did is install facebox_render first, then jRails. You might want to add --force if you are reinstalling.

Make sure that you have the latest jQuery. Include jQuery first then the facebox.js Also, I always make sure that the facebox.css is linked first before the other styles, it might overwrite some of your styles. And verify if you're using FF via view source the js and css links are working.

In addition, verify this line:

<%= facebox_link_to "Sign Up&nbsp;", :url => new_account_path, :method => :get %>

I added the :method => :get to make sure it creates:

<a onclick="jQuery.facebox(function(){ jQuery.ajax({data:'authenticity_token=' + encodeURIComponent('Jbge/CYS4eXQ1d21E/S7tEcTm3dGdStdCtX9MwDx98o='), dataType:'script', type:'get', url:'/account/new'}) }); return false;" href="#">Sign Up&nbsp;</a>

这篇关于Rails/facebox_render-未定义Ajax(facebox始终处于加载状态...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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