如何使用Ajax显示弹出窗口

时间:2019-06-27 10:26:03

标签: ruby-on-rails ruby popup haml

我试图在单击按钮时显示一个弹出窗口,但是由于我总是收到Ajax方法错误消息,所以无法到达它。

我的弹出窗口应如下所示:

https://image.noelshack.com/fichiers/2019/26/4/1561630568-59639851-4278bc80-9154-11e9-965a-d691ee7777b1.png

我试图用已经正常运行的弹出窗口的内容加载弹出窗口,并且该窗口正在运行。我可以通过我的网站显示选定的图像,但不能从弹出窗口中显示。

我想我的模型语法很好,因为我可以显示用户选择的图像,所以我的问题将出在我的Controller语法上。

我的控制器方法:

  def pbbackground
    progress_board = ProgressBoard.find(params[:id])
    if params[:type] == "cover_image"
      result = progress_board.cover_image.save
      progress_board.save(validate: false)
    end
  end

我的模型参数用于添加cover_image

  has_attached_file :cover_image,
                    :styles => { square: "200x200>", small: "400x400>", :large => "640x640>", :thumbnail => "400x400#",to_add: "362x270>", you_might_like: "260x160>" }
  validates_attachment_content_type :cover_image, :content_type => ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/bmp']

  def assign_cover_image
    if ci = params[:progress_board][:cover_image]
     cover_image = ci
    end
    cover_image = File.open(cover_image_path)
    self.cover_image = cover_image
    self.save
  end

我正在使用的Ajax方法:

function loadProgressForm(resource, id){
    $(".form_loader").show();
    if(resource == "new"){
      url = "/progress_boards/new";
      popup_name = "Make A Progress Board";
    } else if (resource == "edit"){
      url = "/progress_boards/" + id + "/edit";
      popup_name = "Add/Remove Metrics";
    } else if (resource == "pbbackground"){
      url = "/progress_boards/" + id + "/pbbackground";
      popup_name = "Add A Picture";
    }
    $.ajax({
      url: url,
      success: function(response, data){
        $("#progress_board_form").html(response.html);
        $("#progress_board_form").find('.modal-title').text(popup_name);
        $(".form_loader").hide();
      },
      error: function(response, data){
        alert("Error loading project form")
        $(".form_loader").hide();
      }
    })
  }

0 个答案:

没有答案