Tag: ruby on rails

将text_field值传递给will_paginate作为Rails中的参数

我有一个Books的控制器,在索引操作中我使用的是will_paginate 。 我还有标题和作者的filter。 每次标题或作者更改时,我都会进行ajax调用以获取@books更新版本。 在我的index.js.erb文件中,我有我的代码来呈现视图: $(‘#book_list’).html(“”); 我的索引文件如下所示: 问题是,AJAX调用后will_paginate不会更新。 默认情况下我有45本书(每页30本书,共2页),在AJAX通话后我得到9本书。 它应该只显示1页,但它仍然显示2页。 如果我把will_paginate放在book_list中 ,它就会消失。 如果我留在外面它将不会更新。 另一个选择是,我可以将自定义参数传递给will_paginate ,但我不知道如何在视图中获取文本字段的值并将其作为参数传递给will_paginate而不提交。 这些是过滤书籍的输入表格:

将参数传递给Rails中的onchange事件

我的rails应用程序中有一个select标签,我想调用showSubTypes函数函数onchange事件 ‘showSubTypes()’ %> 在这里,我想将p.id参数传递给我的showSubtypes函数。 但我不知道如何在rails中做到这一点。

基于来自Jquery和Ajax的combobox中的选定值自动填充表单

我是ajax和Jquery的新手。 我已经编写了代码来通过我正在设计的表单中的ajax调用来自动填充combobox。 现在我想根据combobox中的选定值自动调整相同表单的其余字段,为此我需要另一个ajax调用,它只返回一个student对象。 使用此对象,我可以像这样设置表单的字段: $(‘#student_name’).val(student.name); $(‘#student_roll_num’).val(student.roll_num); etc. 其中name,roll_num是表单字段的id。 我是用以下方式写的: //This following function will get called when one value from the combo box is //selected $(“select#student_id”).change(function(){ var student_id = $(this).val(); //Here I am getting the selected value from //the combo box $.ajax({ url: “/students_database?student_id=”+student_id, //this is the url that will //send me one student object dataType: […]

jQuery对控制器动作的调用并不像预期的那样

我有以下jQuery : var request = $.get(“getPerforceSuites”); request.success(function(result){ alert(“res: ” + result) }) request.error(function(jqXHR, textStatus, errorThrown) { alert (“err: ” + errorThrown); }) 以及routes.rb中的以下条目: get “getPerforceSuites”, to: “perforce_sync#getPerforce” 在我的perforce_sync_controller.rb中 : def getPerforce # return getRemoteSuites puts “++++++++++++++++++++++++++++++++++++++” puts “Called getPerforce” puts “++++++++++++++++++++++++++++++++++++++” return “Hi!” end 最初这不起作用 – 直到我在/ views / perforce_sync中创建一个空的getPerforce.erb.html文件…现在我可以自信地说,getPerforce操作肯定被调用,因为3“put”行出现在rails中服务器日志。 但是,我原本期望“alert(”res:“+ result)”显示“嗨!”……但是,我得到了一大堆HTML,看似是一个文档标题(但是从哪个文件,我我不知道!): res: Test1 ***… […]

如何将变量从AJAX表单传递到控制器?

我有报告(金额,日期)。 我希望用户使用datepickers选择日期并显示在用户选择的日期之间创建的报告。 所以我需要从AJAX表单传递这些变量。 我添加了AJAX表单。 这是我的_form.html.erb : “financial_reports”, :action => ‘report’, :remote => true) do%> From “dd/mm/yy” %> To “dd/mm/yy”%> “btn super”, :id => “btn “%> 我有部分,正在显示报告。 | _financial_report.erb.html Date Amount Currency Total 我在index.erb.html上渲染了这个部分内容 在我的report.js.erb中,我想返回apporpiate报告: $(‘.report’).apppend(”); 这是我的控制器( 我不知道应该在哪里调用“where”条件 def index @financial_reports = current_user.financial_reports#.where(:created_at => the_start.to_date..the_end.to_date) … end 或者在这里 def report @financial_reports = current_user.financial_reports#.where(:created_at => the_start.to_date..the_end.to_date)//here respond_to […]

正在调用Bootstrap Switch JS,但什么都不做

我正在使用bootstrap和jQuery,但我目前正在尝试添加Bootstrap Switch。 我开始采取行动,因为我无法让它发挥作用。 从检查元素看,js似乎没有修改任何html。 我试过使用gem或直js / css。 我从gem中尝试了sass和css。 不管它看起来像js什么也没做。 如果我删除bootstrap-switch js文件然后我得到一个错误(这是有道理的),所以我知道它被调用。 它什么都没做。 以下是我的设置: gem Using sass (3.3.2) Using bootstrap-sass (3.1.1.0) Using bootstrap-switch-rails (2.0.2) Using jquery-rails (3.1.0) Using sass-rails (4.0.1) Application.css.scss @import “bootstrap”; @import “bootstrap3-switch”; 的application.js //= require jquery //= require jquery_ujs //= require bootstrap //= require bootstrap-switch // //= require_tree . other.js $(“#famous-people-switch”).bootstrapSwitch(); some.html.erb Famous […]

AJAX / HTTP问题

我有一个链接的代码,评估是否有标签来确定链接文本应该说什么: ‘edit_topics_link’, :class => ‘edit’ %> 问题是我的标记系统完全使用AJAX更新,而这个链接文本没有,所以它只在页面刷新后更新为正确的链接文本。 如何使用AJAX更新文本?

rails 3.2中的jQuery datetimepicker格式

我正在使用以下datetimepicker,根据我的理解,它是已扩展的jquery-ui datepicker。 http://trentrichardson.com/examples/timepicker/ 我的问题是我想向用户显示上午和下午时间,但我想以不同的方式对其进行格式化,以便当我将其提交到mysql数据库时,时间格式进入标准“YY-mm-dd – hh:mm: ss“格式。 这是它当前输入的格式

Rails 5 – 使用bootstrap datepicker,除非浏览器支持HTML5日期控件

我试图在浏览器支持时使用date_field HTML5日期控件组合一个有效的解决方案,如果没有,则回退使用Bootstrap Datepicker 。 看起来这是一个常见的解决方案,但我找不到适用于我的解决方案(即,不涉及为每个日期字段手动添加隐藏字段的解决方案,因为我已经有了一堆一些页面)。 使用此文档作为指南,我有一个部分工作的解决方案(使用FireFox 49.0.2进行测试): dates.js.coffee: datepicker = $.fn.datepicker.noConflict() # return $.fn.datepicker to previously assigned value $.fn.bootstrapDP = datepicker # give $().bootstrapDP the bootstrap-datepicker functionality formatDateToPicker = (dateStr) -> # dateStr is what Rails emits “yyyy-mm-dd” parts = dateStr.split(‘-‘) if dateStr == ” return ‘NoDateProvided’ else if parts.length == 3 return “#{parts[1]}/#{parts[2]}/#{parts[0]}” else […]

Rails在使用Ajax时返回多个重复记录

所以,我有一个应用程序,有几个电影剪辑,用户可以搜索特定主题等…我正在使用Ajax处理分页,以便用户可以进行搜索查询并滚动查看更多结果(类似于推特)。 问题是当用户搜索即“搞笑”时,会出现一堆记录,并且当用户向下滚动时,Ajax将使用新记录加载记录的副本。 这是代码: if $(‘.pagination’).length $(window).scroll -> url = $(‘.pagination .next_page’).attr(‘href’) if url && $(window).scrollTop() > $(document).height() – $(window).height() – 50 $(‘.loader’).removeClass(‘hidden’) $.getScript(url) $(window).scroll() 这是一个截图 在这种情况下,如何防止rails重复记录? 我尝试过uniq和其他几种方法无济于事。 谢谢! 在这里更新一些可能有助于调试此问题的其他代码: https://gist.github.com/pblogs/e202ee1f03339ba977ec