Ajax渲染:remote =>真的不适用于Firefox

时间:2015-09-02 17:22:48

标签: javascript ruby-on-rails ajax firefox firebug

我的控制器操作: advertisment_controller.rb

class AdvertismentsController < ApplicationController
  before_action :set_advertisment, only: [:show, :edit, :update, :destroy]

  before_filter :authenticate_user!
  skip_before_filter  :verify_authenticity_token

  layout 'admin'

  respond_to :html

  # GET /advertisments
  # GET /advertisments.json
  def index
    @advertise_tab = 'active'
    if current_user.is_super_admin?
      @advertisments = Advertisment.all
    elsif current_user.is_admin?
      @advertisments = current_user.mediums.last.advertisments
    elsif current_user.is_agent?
      @advertisments = Advertisment.all.collect{|ad| ad if (ad.discount_rate.present? && ad.discount_rate.discount_provider == current_user.id) }.delete_if{|x| x == nil}
    elsif current_user.is_member?
      @advertisments = current_user.advertisments
    end
  end

  # GET /advertisments/new
  def new
    if current_user.is_agent? || current_user.is_member?
      @advertise_tab = 'active'
      @advertisment = Advertisment.new
      load_ad_components
    else
      redirect_to advertisments_path, flash: {error: 'You cannot create an advertisment'}
    end
  end

  # GET /advertisments/1/edit
  def edit
    @mediums = Medium.all
    @discount_rates = current_user.discount_rates.where(:media_category_id => @advertisment.media_category_id)
    @draft_advertisments = current_user.advertisments.where(:draft => true)
    respond_to do |format|
      format.js
    end
  end

  # POST /advertisments
  # POST /advertisments.json
  def create
    @advertisment = current_user.advertisments.new(advertisment_params)
    @advertisment.save
    load_ad_components
    respond_to do |format|
      format.js
    end
  end

  # PATCH/PUT /advertisments/1
  # PATCH/PUT /advertisments/1.json
  def update
    @advertisment.update(advertisment_params)
    load_ad_components
    respond_to do |format|
      format.js
    end
  end

  # DELETE /advertisments/1
  # DELETE /advertisments/1.json
  def destroy
    @advertisment.destroy
    flash.now[:success] = "Advertisement deleted successfully."
    load_ad_components
    respond_to do |format|
      format.js
    end
  end

end

我的广告/ _form.html.erb

<%= form_for(advertisment, :multipart => true, :remote => true) do |f| %>
    // form fields 
    // advertisment is a local parameter  
<% end %>

现在,如果我提交此form,它会将控制器create方法请求为html而不是js。 另外,对于edit,我创建了链接 <li><a href="<%= edit_advertisment_path(ad) %>" data-remote="true">Edit</a></li>

但是当我点击编辑链接时没有任何反应。在firebug控制台中没有显示ajax调用。我的application.js文件包含

//= require jquery.min.js
//= require jquery_ujs

这里有什么不对?顺便说一句,我已经用Chrome浏览器中提到的ajax渲染测试了整个编辑,创建,更新,销毁,并且它的工作正常。有没有人知道这个代码在firefox中有什么问题?

N.B。 Firefox的firebug告诉我两个js文件(jquery.min,jquery_ujs)都已加载。我删除了browser cache。但仍然是一样的。 :'(

任何帮助将不胜感激。

0 个答案:

没有答案