问题
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!
回答1:
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 ", :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 </a>
来源:https://stackoverflow.com/questions/3980844/rails-facebox-render-ajax-is-not-defined-faceboxs-always-loading