Tag: ruby on rails 3

rails 3如何使用jquery提交远程表单并避免回调

我有一个remote => true表单,并希望提交它并避免提交方法。 通常我会这样做 form$.get(0).submit() form$.submit(function(){..avoid going here..}) 但这会将表单发送为html而不是js。 有没有办法做到这一点并获得js作为回应? 谢谢!

如何为javascript函数设置和获取check_box_tag的ID?

我有一个带有check_box_tags的Ruby on Rails 3表单。 如何设置ID然后在javascript函数中获取值? 这是check_box_tag IP Phones 我的javascript $(document).ready(function() { $(‘#device’).change(function(){ if (($(‘#device’).val() == “IP Phone”) || ($(‘#device’).val() == “IP PBX Systems”)) { $(‘#phonepbx’).css(‘display’, ‘none’); } else { $(‘#phonepbx’).css(‘display’, ‘inline’); } }); }); 我不知道如何设置和获取check_box_tag的id。 我试图根据他们选择的内容显示或隐藏div id =“phonepbx”。 如果他们选择前两个复选框之一,我想显示#phonepbx div。 否则将其隐藏起来。 谢谢 编辑这是HTML最终的结果: IP Phones 我确实需要jquery并需要jquery_ujs。 我需要别的东西吗? 解 function checkHardware() { if ($(‘#device input:checkbox:eq(0)’).is(‘:checked’) || […]

jQuery正确执行但只进行一次更改

我有这个rails3应用程序,在每次用户选择分数…(提交表单。)时,我想要更新的弹出div中显示得分,计算得分并在AJAX中返回。 这有效,我可以在以下JavaScript中放置一个断点: $(‘#eval_form’) .bind(“ajax:beforeSend”, function (evt, xhr, settings) { xhr.setRequestHeader(‘accept’, ‘*/*;q=0.5, ‘ + settings.accepts.script) }) .bind(“ajax:success”, function (evt, data, status, xhr) { var $response = xhr.responseText var encoded = jQuery.parseJSON($response) $(‘#scoretotal’).replaceWith(‘Total Evaluation Score: ‘ + encoded.scores[0]) //also change button text $(‘#score-popup’).attr(‘value’, ‘testing value’) }); }); encoded.scores[0]和`encoded.scores [1]等于他们想要的。 jQuery的其余部分执行,第一行得分总计工作正常,它确实会改变那个分数……随后新商店的任何时候,它只是不更新​​或不再替换… 不仅如此,还有按钮 值不会随着上面的jquery甚至是.prop而改变我不知道为什么这样做会让人感到不安…这里是视图中的其余代码: x OVERALL EVALUATION RATING Total […]

任何机构都可以告诉我如何在cent os中打开扩展名为.dat的FIle吗?

在我的新Ruby on rails应用程序中,我想找到用户的国家代码。 所以我使用的是MaxMind GeoIp。 当我在gunzip之后下载gzip文件时,它给了我一个GeoIP.dat文件,我被困在这里。 任何人都可以帮忙。 如果他们是打开它的程序或某些程序来使用它。 或者,如果任何人可以建议我另一种方式。

如何使用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

如何在rails控制器中格式化json?

如何在rails控制器中格式化json? 通过link_to我发送并获取方法参数[:cat],然后我通过父(params [:cat])获取所有子项,但是如何以json格式为我的jqTree格式化这一切? 所以它看起来像{label :(这里是params [:cat]),孩子:[{all @ search_trees.id}]}? require ‘json’ @search_trees = SearchTree.find(:all, :include => [:designation], :conditions => { :STR_ID_PARENT => params[:cat]}) #data = “{ label : ‘10001’, children : [{label : ‘10111’},{label : ‘10122’}] }” respond_to do |format| format.html # index.html.erb format.xml { render :xml => @search_trees } format.json { render :json => data […]

Javascript在rails app中无效

我在store.html.erb文件中有这个代码 “line-item”, :product => product.id %> $(‘document’).ready(function(){ $(“.line-item”).click(function(){ var prod = $(this).attr(‘product’); $.ajax({ url:”, data: {product_id: prod}, type: ‘POST’, dataType: ‘script’ }); }); }); 我的line_items_controller.rb有这段代码 def create @cart = current_cart product = Product.find(params[:product_id]) @line_item = @cart.add_product(product.id) respond_to do |format| if @line_item.save format.html { redirect_to(store_url) } format.js { @current_item = @line_item } format.xml { render :xml […]

Javascript没有加载最新提交的数据

我最近问过这个问题: Javascript Form Submition ? 现在我想弄清楚为什么在表单提交后, create.js.erb不会加载最新数据(提交的数据)。 如果我再次提交数据,表格将使用倒数第二个数据更新,但不会更新绝对最新数据。 …为什么? 编辑: 最新代码 – 类别控制器:类Admin :: CategoriesController <Admin :: AdminController … def create @category = Admin::Category.new(params[:admin_category]) # You can’t retrieve the @categories before attempting to add new one. Keep at end of create method. @categories = Admin::Category.all respond_to do |format| if @category.save save_to_history(“The category \”#{@category.name}\” has been […]

部分显示操作不会显示在索引视图中 – rails

我在一个名为properties / _property_details.html.erb的部分中有我的show动作,我试图在索引动作的视图中用ajax显示。 性能/ index.html.erb: ‘property_details’ %> 性能/ _property_details.html.erb: etc etc 但是,当我尝试加载索引页面时,show动作的@property变量为零,所以我得到了一个 undefined method `Address’ for nil:NilClass 大概是因为在properties_controller中需要show动作没有(params [:id]): def show @property = Property.find(params[:id]) respond_to do |format| format.js {render :partial => ‘property_details’ ,:layout => false} format.html end end 但是如果是这种情况那么我应该能够在show动作中为@property硬编码只是为了测试这个但是当我尝试加载包含部分的索引页时,下面的代码仍然为nilclass错误提供相同的未定义方法: def show @property = Property.find(1) respond_to do |format| format.js {render :partial => ‘property_details’ ,:layout => false} […]

Rails / facebox_render – 没有定义Ajax(facebox总是加载…)

我试着用facebox_render和rails 3做一个简单的测试。 这是我的步骤: 1.)安装Jquery 1.4.2(Jrails) 2.)安装插件rails插件安装git://github.com/ihower/facebox_render.git 3.)并添加以下行: 在我的application.html.erb中 在我的application_controller中 class ApplicationController < ActionController::Base include FaceboxRender end 当我试图在facebox中加载东西时,我只有加载器,没有任何东西出现…… 例如,在我的home / index.html.erb中 “/images/rails.png” %> 我很高兴知道我错在哪里,在文档中: * facebox_link_to helper, it’s will launch loading facebox first, send ajax request second) * link_to :remote => true, form_for :remote => true …etc Ajax helper (for Rails 3) 所以我觉得我不得不发送ajax请求.. 看了下面的post: 如何使facebox弹出窗口保持打开状态,并且提交后facebox内的内容发生了变化 ,似乎我遇到了同样的问题:我可以在你的firebug控制台中看到“Ajax未定义” […]