我在我的application.js文件中进行此调用,但它似乎没有从用户输入的链接返回动态生成的嵌入视频:
$("#new_video").bind('submit', function(e){
e.preventDefault();
var q = $(this).find('#video_video_url').val();
if (q == '')
return false;
$.embedly(q, {maxWidth: 500, wrapElement: 'div' }, function(oembed, dict){
if (oembed == null)
$(".video").html('<p class="text"> Not A Valid URL </p>');
else
$(".video").html(oembed.code);
})
});
我不确定'submit'
所在的地方应该是什么,所以这可能会给我带来麻烦。
用户输入网址的表单的我的ID为#new_video
,字段的ID为#video_video_url
,而我的视频部分生成了类video
:
<%= div_for video do %>
<% end %>
这是在index
视图中呈现的,我想在其中显示所有嵌入的视频。这就是我index
视图中我想要嵌入所有视频的全部内容:
<div id ='video_div'>
<%= render @videos %>
</div>
然而,它不起作用。没有嵌入视频。我究竟做错了什么?请记住,我不仅要在提交网址后嵌入视频,还要存储网址,并希望将来无限期地显示嵌入的视频。
以下是浏览器在new
视图中看到的表单的HTML:
<div id="dialog" class="window" style="top: 237px; left: 435px; display: block; ">
<form accept-charset="UTF-8" action="/videos" class="new_video" id="new_video" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" value="h/yzzD0lWsp7nc89WPmDRXWs5ahdfUc3ZvY5IukX2fQ=">
</div>
<div class="field">
<label for="video_video_url">Video url</label><br>
<input id="video_video_url" name="video[video_url]" size="30" type="text">
</div>
<div class="actions">
<input id="video_submit" name="commit" type="submit" value="Create Video">
</div>
</form>
<a href="#" class="close">Cancel</a>
</div>
更新:
我在控制台中收到此错误:
Started GET "/jquery.embedly.js" for 127.0.0.1 at Thu Mar 17 00:09:29 -0700 2011
ActionController::RoutingError (No route matches "/jquery.embedly.js"):
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)
我在应用程序布局中包含了jquery.embedly.js,但是......
答案 0 :(得分:1)
看起来错误是它没有加载Embedly jQuery脚本。这解决了吗?或者,您可以从托管的http://scripts.embed.ly/jquery.embedly.js页面加载Embedly jQuery脚本。
答案 1 :(得分:0)
HTML是什么样的?你确定要在#video_video_url上使用.val()而不是html()或attr('href')吗?我认为您使用.val()作为输入值。
来自val()jquery docs:“。val()方法主要用于获取表单元素的值。”
更新:刚刚看到你的描述,你确实说是来自用户输入。所以不要理会上面。你能粘贴HTML吗?
更新#2:加载嵌入脚本可能会出现问题。你使用的是最小版本吗?你能检查一下,确保文件名是一样的吗?似乎如果jquery被加载,它也应该加载嵌入。