Tag: ruby on rails

Jquery Rails 3 …表单提交两次…删除两次…帮助

似乎eveyone有这个问题,但没有人有一个外行人的条款答案,甚至没有一个适当的解决方案。 我有一个表单,使用ajax提交表单,并自动将其添加到文本字段下面的列表中。 表单提交两次,因此我有两个相同的(除了ID)记录。 更糟糕的是当你试图删除它不会更新页面,因为它试图删除相同的记录两次。 我希望有人在那里有一个很好的答案…顺便说一句我对rails的新意见。 码: index.html.erb SSCC @orderlines.reverse %> _form.html.erb true) do |f| %> _order_line.html.erb | | ( ‘Are you sure?’, :method => :delete, :remote => true %>) create.js.erb $(‘#orderlines’).prepend(”); $(‘#orderlines > li:first ‘).effect(‘highlight’, {}, 3000); $(‘#orderline_form > form’)[0].reset(); destroy.js.erb $(‘#’).css(‘background’, ‘red’); $(‘#’).hide(“fade”, {}, 1500);

Element.update不是函数

我正在尝试将JQuery集成到Rails 3.我已经从http://github.com/rails/jquery-ujs下载了rails.js文件并将其包含在我的应用程序中。 我还包括JQuery。 但是当我尝试做一个简单的page.replace时: render :update do |page| page.replace_html “my_div”, :partial => “my_partial”, :locals => {:mylocal => mylocal} end 我从javascript执行中抛出以下错误: RJS error: TypeError: Element.update is not a function Element.update(“my_div”, “mypartialdata”); 有任何想法吗?

onchange显示/更改部分

使用select有一个下拉列表 “?” )%> 有部分称为“forms” 每当选择发生变化时,我都需要渲染部分。 如果有办法,请告诉我。 我发现remote_functionfunction已从rails 3.0弃用。 我在这里看到了所有可能的链接onchange和select标签,但找不到合适的答案。 我是rails,jQuery和Ajax的新手。 请帮忙 谢谢

如何让Adam Shaw的FullCalendar在rails 4 app中显示响应

我正在使用Ruby 2 Rails 4.我正在使用twitter-bootstrap-rails gem让我的导航栏在浏览器resize时崩溃。 我想要与Adam Shaw的FullCalendar类似的效果。 现在它将调整窗口大小,但我希望它在浏览器为480px或更低时显示一天(basicDay视图),在视口低于767时显示一周(basicWeek视图),以及完整显示月视图大小的窗户。 在不同大小的浏览器中,我最好初始化三个不同的日历吗? 即: $(document).ready(function() { // page is now ready, initialize the calendar… $(‘#calendar’).fullCalendar({ events: ‘http://www.google.com/calendar/myfeed’, if $(window).width() < 514){ defaultView: 'basicDay' } header: { left: 'title', center: '', right: 'today basicDay basicWeek month prev,next' }, }); }); 还是有一个更简单,更简单的解决方案? 另外,我真的很陌生,我知道上面的示例代码不会像写的那样工作,但我至少在正确的轨道上吗? 谢谢,对不起,如果这是写在别的地方,我找不到,但如果有人指出我正确的方向会很高兴。 更新: 为了响应第一条评论,为了让它工作,我进入了fullcalendar.js并改变了主渲染的工作方式(第240行) /* Main Rendering —————————————————————————–*/ setYMD(date, […]

JQuery .on()没有将点击事件绑定到动态创建的元素

我有一个文本框,当我按Enter键时动态添加一个元素,另一个文本框在我单击删除按钮时删除该元素。 delete方法适用于任何现有元素,但不适用于动态插入的任何元素。 这是代码: $ -> # AJAX to add a new stock $(“#add-symbol”).keypress (e) -> if e.which == 13 url = $(this).data(‘url’) name = $(this).val() $.ajax url: url type: “POST” data: { user_id: $(‘#info’).data(‘user-id’), name: name } success: (response) -> if response.status == 200 new_element = ”+ response.symbol + ” $(‘#symbols’).append(new_element) $(‘#add-symbol’).val(”) else #deal with […]

Rails通过ajax提交表单并更新视图

我想通过ajax更新表单提交而不重新加载页面并根据它更新视图。 我尝试了不同的方法,并因为我对rails的新手而失败了。 这是情况。 在模态中 def new @new_entry = current_user.notes.build @words = current_user.notes @notes_false_list = current_user.notes.where(known: false).order(“title”).group_by { |note| note.title[0] } @notes_true_list = current_user.notes.where(known: true).order(“title”).group_by { |note| note.title[0] } end 在视图中的表单代码。 {:class => ‘home-form without-entry clearfix’} do |f| %> 创建动作 def create @new_note = current_user.notes.build(new_note_params) if @new_note.save @notes_list = current_user.notes.count unless @new_note.user.any_entry @new_note.user.toggle!(:any_entry) if @notes_list >= […]

Rails 4:点击后禁用提交按钮

我有一个form_tag(foo_path(@foo), remote: true, id: ‘foo-form’表单和一个提交按钮submit_tag (“Submit”, :id => “foo-submit”) 我想在点击后禁用提交按钮。 显然,我不能使用onlick=”jQuery(this).prop(‘disabled’, true);” 因为它会打破远程function。 我知道:disable_with submit_tag的:disable_with数据属性,但它似乎对我不起作用。 它确实生成了正确的表单代码,但它没有任何效果。 我不确定它为什么不起作用,但可能是因为我同时使用原型(遗留原因)和jquery。 虽然,我只为jquery而不是原型加载ujs 。 但是,所有其他query_ujsfunction都可以正常工作。 还有其他方法可以禁用提交按钮吗?

Rails:通过Ajax渲染部分

我有一个带有选项卡的页面,我想在单击选项卡时通过ajax呈现不同的部分。 我有一些代码,但我不认为这是最有效的方式。 我希望是否有人可以帮助我使用已经存在的代码,或者如果有更简单的方法我会非常感激。 谢谢! HTML标签 true, :class => ‘TabText’ %> @microposts %> 学校管理员 class SchoolsController 3, :page => params[:page]) respond_to do |format| format.html format.js end end end 最近的JS $(“#ContentBody”).html(‘ “users/microposts” )%>’); 路线 resources :schools do collection do get :mostrecent end end

活动管理员,首先填充第二个下拉列表中的一个

我正在使用单词来进行类别映射。 单词可以映射到类别或类型。 在数据库中,我有单词表,类别表,类型表和名为word_categories的连接映射,其中包含word_id,cat_type(具有类别或类型的值),cat_id(如果cat_type是类别,则cat_id对应于类别表,或者如果cat_type是类型,cat_id对应于类型表)。 在主动管理关键字_categories.rb我有 form do |f| f.inputs do if f.object.new_record? f.input :word, as: :select, collection: Word.unmapped.pluck(:word) f.input :cat_type, as: :select, :collection => [“Type”, “Category”] if true #here i have to give some logic to select on the basis of the value selected in the first drop down f.input :cat_id, as: :select, :collection => Type.pluck(:name) […]

在rails 3升级后重新定位时出现回形针错误

我有回形针工作上传和保存图像的不同样式但是当我使用来自railscasts教程的jcrop来裁剪图像时它不会裁剪图像。 我收到这个错误 [paperclip] identify -format %wx%h ‘/var/folders/z+/z+KzOZBFE9irCpbMKKBGFk+++TI/-Tmp-/paperclip-reprocess20110118-19757-1wtrjaj-0[0]’ 2>/dev/null [paperclip] convert ‘/var/folders/z+/z+KzOZBFE9irCpbMKKBGFk+++TI/-Tmp-/paperclip-reprocess20110118-19757-1wtrjaj-0[0]’ -crop 28×32+13+15-resize “400×400>” ‘/var/folders/z+/z+KzOZBFE9irCpbMKKBGFk+++TI/-Tmp-/paperclip-reprocess20110118-19757-1wtrjaj-020110118-19757-1a5n558-0.jpg’ 2>/dev/null [paperclip] An error was received while processing: # 这是在rails 2.3.9中工作,但是hvae刚刚升级到rails 3.0.3我已经获得了所有最新的gem等。 cropper.rb文件如下所示,位于初始化程序目录中 module Paperclip class Cropper < Thumbnail def transformation_command if crop_command crop_command + super.join(" ").sub(/ -crop \S+/, '') else super end end def crop_command target = @attachment.instance if […]