Tag: ruby on rails

jQuery DOM事件监听器失败,“$未定义”

按照这里的建议,我在Ruby on Rails应用程序中有以下内联代码: document.addEventListener(“DOMContentLoaded”, function(event) { $(“select#graph_line_duration”).change(function(){ $(“form”).submit(); }); $(“input#graph_duration”).hide(); }); 我收到错误$ is not defined 。 但是,如果我单击链接转到页面,那么代码工作正常,所以我的jquery资产正在加载,给定足够的时间。

Rails 3:原型到jquery问题

如何将这些create.js.erb和destroy.js.erb文件从原型切换到jquery? create.js.erb $(“follow_form”).update(“”) $(“followers”).update(”) destroy.js.erb $(“follow_form”).update(“”) $(“followers”).update(”) 这是我在我的应用程序中唯一的原型,我想切换到jquery并开始从那里学习。 谢谢你的帮助!

JavaScript Post Request w / Image

我恐怕我可能已经知道答案了。 我希望离线呈现HTML5表单,用户可以在其中选择要上载的图像。 一旦用户重新上线,图像将被上传。 我可以从文件输入中提取所有数据,但有没有办法通过post发送数据以保存服务器上的blob? 我正在使用jQuery并且有一个Rails后端(典型的文件上载通过CarrierWave处理)。

使用AJAX和JQuery在设定的时间间隔刷新rails部分

我的rails应用程序中有一个页面,如下所示: 现在,我有另一个用python编写的AI应用程序来处理video(显示在rails应用程序页面的左侧),并使用捕获的车辆及其相应的牌照填充数据库(显示在rails应用程序中的video旁边) 。 意思是说,rails和python应用程序有一个共享数据库。 我现在要做的是,我想刷新右边的部分,比如说每10秒一次,这样它就会显示新添加的车辆。 我从这个堆栈溢出post中模拟了我当前的解决方案,我能够确认我可以成功呈现js页面,如我的日志中所示: 但是,尽管添加了新条目,部分仍然只显示一个条目。 我需要手动刷新页面才能显示所有新条目。 我不确定我犯了什么错误。 以下是我目前的相关代码: application.js //负责部分刷新 $(document).ready(function () { setInterval(refreshPartial, 1000); }); function refreshPartial() { $.get(“/single_live.js”, function(data){ $(“#captured_vehicles_live”).html(data); }); } static_pages_controller.rb def single_live @all_captured_violators = CapturedViolatorPlaceholder.all.order(‘capture_date DESC’) respond_to do |format| format.html format.js end end single_live.html.slim .ui.container style=”margin-top: 100px;” .ui.container h1.ui.center.aligned.header Camera 1 .ui.divider .ui.left.aligned.grid.stackable .ten.wide.column .ui.segment image[src=”http://62.242.189.219:80/mjpg/video.mjpg?COUNTER” style=”border: 0 […]

如何在Rails中使用Ajax和Jquery将图像上传到Amazon AWS(S3)?

我希望用户从网站上传他们的图片。 我已经完成了大部分工作但是现在,我在将图像上传到服务器时遇到了困难。 我该如何解决这个问题? HTML – “> X Delete Cancel  Upload Here <input type="hidden" name="user_id1_key" value="”/> 咖啡脚本 – $ -> if $(‘#target1 img’).length == 1 $(‘#file_browser1’).addClass ‘none’ $(‘#close1’).addClass ‘delete1’ $(‘#closebtn1’).on ‘click’, (e) -> $(‘#closemsg1’).addClass ‘msg1’ $(‘#cancelbtn1’).click -> $(‘#closemsg1’).removeClass ‘msg1’ $(‘#deletebtn1’).click -> $(‘#close1’).removeClass ‘delete1’ $(‘#closemsg1’).removeClass ‘msg1’ $(‘#target1 > img’).hide() $(‘#file_browser1’).removeClass ‘none’ $(‘#file-upload1’).val(”) return $(‘#file-upload1’).on ‘change’, (event) […]

Ruby on rails cocoon gem – 无法捕获回调事件

嗨我目前正在使用我的rails应用程序的cocoon gem,它似乎工作正常,因为我能够添加和删除我的表单中的嵌套关​​联。 但是,当我尝试控制日志回调时(例如“cocoon:after-insert”),控制台上没有触发控制台日志。 可能是什么原因以及如何在我的控制台中捕获回调事件? 我也在我的应用程序中捆绑了gem remotipart,如果这可以提供任何线索,为什么我无法捕获我的控制台上的回调。 她是我的代码: – #new.html.erb {:class => ‘ui form’}, :remote => true do |f| %> “”, class: “ui button” %> #_tactics_fields.html.erb # application.js $(document).on(‘turbolinks:load’, function() { $(‘#tactical_field’).bind(‘cocoon:before-insert’, function() { console.log(‘helloworld’); }); });

jQuery ajaxSubmit调用总是返回一个带有response.statusText =’n / a’的0响应代码

背景:jquery 1.5.2,ruby on rails。 主要问题似乎是我得到一个0响应代码,无论Web服务器告诉我它返回什么。 我有一个应用程序在模型validation失败时返回422,但由于某种原因,每次调用成功函数。 $(“#form”).ajaxSubmit({ dataType: ‘json’, success: function(data, status, response) { // stuff }, error: function(data) { // stuff } }); 当我调试.log所有内容时,这就是我所看到的: POST http://site/favicons 422 (Unprocessable Entity) data: Object favicon: “Image must be 16×16 pixels” __proto__: Object status: success response:Object abort: function (status) { aborted: 0 getAllResponseHeaders: function () {} getResponseHeader: function […]

什么可能导致Bootstrap模式不留在屏幕上?

我在我的应用程序中使用Bootstrap模式,我正在尝试执行股票Bootstrap模式作为概念certificate(即从模态工作的基线开始,然后从那里构建)。 在我的_notifications.html.erb我有这个: Launch demo modal ×Close Modal title … Close Save changes 问题是当我点击它时,模态出现的时间为1/10秒,然后消失。 这就是我的application.js样子: //= require jquery //= require jquery_ujs //= require jquery.turbolinks //= require best_in_place //= require main.js //= require bootstrap //= require bootstrap-sprockets //= require jquery-ui/datepicker //= require best_in_place.jquery-ui //= require jquery.purr //= require best_in_place.purr //= require bootstrap.file-input //= require chosen.jquery //= require […]

使用typeahead.js创建可点击的动态链接

我想在我的搜索自动完成链接到网站上的特定餐厅的建议结果。 注意:我遇到过这篇文章,但它使用了一个静态的对象数组。 与这篇文章不同,我希望从服务器端生成链接。 var links = [{name: “abc”, link: “http://www.example1.com”}, {name: “nbc”, link: “http://www.example2.com”}]; var source = new Bloodhound({ … local: links }); 在我的情况下,我从Rails查询数据库,因此name将是餐厅的名称, link将是restaurant_path 。 基于我目前的代码,我如何才能实现这一目标? 如果需要任何其他代码,请与我们联系。 $(function() { var restaurants = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace(‘name’), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: “/search/autocomplete?query=%QUERY”, wildcard: “%QUERY” } }); restaurants.initialize(); $(‘#autocomplete’).typeahead(null, { displayKey: ‘name’, source: restaurants.ttAdapter() }); […]

错误未定义方法`remote_function’(如何使用remote_function使用Rails 3进行Ajax调用)

我发现这个函数(remote_function)是Prototype帮助器的一部分,它是用Rails 3.1从框架中删除的,以及如何更改ajax? country %select#country{:name => “country”, :onchange => remote_function(:update => ‘region_city’, :url => { :action => :get_regions_cities_for_country}, :with => ‘Form.Element.serialize(this)’)} = options_for_select( Country.find(:all).map {|u| [u.name,u.id]}) %div{:id => “region_city”} region %select#region{:name => “region”, :onchange => remote_function(:update => ‘city’, :url => { :action => :get_cities}, :with => ‘Form.Element.serialize(this)’)} = options_for_select(Country.find(:first).regions.find(:all).map {|u| [u.name,u.id]}) city #{select_tag(:city, options_for_select( Country.find(:first).regions.find(:first).cities.find(:all).map {|u| […]