Tag: ruby on rails

使用jquery UI确认表单提交

我正在尝试确认使用ruby on rails创建的提交表单,但在提交之前我有条件打开确认弹出窗口,询问用户是否真的想要这样做。 这适用于默认的确认浏览器框。 但现在我正在尝试使用Jquery UI,但它不起作用。 如何使用jquery ui返回true或false? 如果用户单击“是”,则应提交表单,如果“否”则应该关闭 这是我的jquery ui函数: function confirm(message, callback) { $(‘body’).append(”+message+”); $( “#confirm” ).dialog({ resizable: false, title: ‘Confirm’, zIndex: 99999999, modal: true, buttons: [ { text: “Yes”, click: function() { $(this).dialog(“close”); if ($.isFunction(callback)) { callback.apply(); } } },{ text: “No”, click: function() { $(this).dialog(“close”);} } ], close: function(event, ui) { […]

rails3 rails.js和jquery捕获ajax请求的成功和失败

以前,在rails 2.3.8中,我使用了prototype-helpers link_to_remote和form_remote_for (以及其他)。 这些可以选择:update如下: link_to_remote “Add to cart”, :url => { :action => “add”, :id => product.id }, :update => { :success => “cart”, :failure => “error” } ( 文档中的一个例子)。 这个例子在成功更新带有“cart”类的html元素时,失败后会出现类“错误”。 现在我相信作案手法已经改变,而是我们写道: link_to “Add to cart”, :url => {:action => “add”, :id => product.id}, :remote => true 并且没有选项设置:update 。 而不是普通的html,我们现在渲染javascript,就像这样(在jquery中): $(‘.cart’).replaceWith( ‘cart’) %>) 但是你如何处理错误情况呢? […]

Rails 4使用ajax,jquery,:remote => true和respond_to呈现部分

看起来像使用AJAX动态渲染页面以响应提交的表单很常见。 其他类似问题都没有集中在如何以一般方式执行此操作。 我能找到的关于这个主题的最好的博客文章是: http : //www.gotealeaf.com/blog/the-detailed-guide-on-how-ajax-works-with-ruby-on-rails 问题:我如何对rails应用程序进行编码,以便在提交表单或单击链接时通过AJAX触发部分视图加载?

是否可以使用Ajax频繁刷新部分?

在后台,我希望它重新加载并显示有多少未读消息。 我希望没有刷新页面。 我的意思是使用ajax。 如果我在菜单中有这个,我怎么能每隔30秒刷新一次这个部分? <%= link_to sanitize(' ‘) + “received messages” + sanitize(‘ ‘+current_user.mailbox.inbox(:read => false).count(:id, :distinct => true).to_s+”), messages_received_path %> messages_controller.rb def received if params[:search] @messages = current_user.mailbox.inbox.search_messages(@search).page(params[:page]).per(10) else @messages = current_user.mailbox.inbox.page(params[:page]).per(10) end add_crumb ‘Messages Received’, messages_received_path @box = ‘inbox’ render :index end 更新: _ __ _ __ _ __ _ __ _ _ […]

jQuery发布到Rails

我的设置:Rails 3.0.9,Ruby 1.9.2,jQuery 1.6.2 我有一个表单,为用户显示多张照片和评论,我希望实现内联评论。 Summer 2011 Write a commenthttps://stackoverflow.com/questions/7237720/jquery-post-to-rails/… Seeing a movie Write a commenthttps://stackoverflow.com/questions/7237720/jquery-post-to-rails/… 我想在用户点击textarea字段中的回车键时提交一个AJAXpost。 这是我到目前为止的javascript(不完整) $(‘#newsfeed’).delegate(‘.comment_box’, ‘keydown’, function (event){ event.preventDefault(); $.post(‘/sub_comments’, https://stackoverflow.com/questions/7237720/jquery-post-to-rails/…); }); 我正在使用delegate方法,因为 内容可以用另一个AJAX调用替换。 我需要的是jQuery post方法的语法,假设我需要传递一些forms参数,比如说photo_id等等。假设我有办法访问params的值,那么post调用创建params的语法是什么Rails期待他们 这是标准的Rails位 sub_comments_controller.rb def new @sub_comment = SubComment.new respond_to do |format| format.html # new.html.erb format.js end end 另外我不想使用通常的 true) do |f| %> true) do |f| %>我可以添加的每个内联评论。 […]

link_to和remote => true + jquery:怎么样? 救命?

我试图在我的rails网站的索引上建立一个“用户”链接,以便它显示注册用户(User.all)但我希望它出现在网站的右侧部分,作为部分,在没有div从头开始加载整个页面。 我知道这可能是旧的原型和远程=>真,但使用Rails 3.1和jQuery(和资产)我不知道如何做到这一点。 任何人都可以帮助或告诉我教程的方法吗?

Rails通过ajax闪烁通知

长话短说,我有一个按钮。 点击它,我想要一个ajax请求被触发,它获取flash [:notice]并将其显示在$中的div中 这是我的简短观点: 我在视图中的ajax请求: $(“#search”).submit(function(){ $.ajax({ type: “POST”, url: //url to my show action success: function(data){ /*$(“#notice”).html(“”); $(“#content”).html(data);*/ } }); return false; }); 我的控制器: def HomeController ‘search’ end end 我的show.js.erb #app/views/dashboard_home/show.js.erb $(“#notice”).html(“”); $(“#content”).html(“”); 问题是当我点击按钮时,通知显示正常。 但同样的通知仍然存在于下一次点击中。 搜索部分包含表格请帮忙!