小编jvi*_*ian的帖子

如何从javascript隐藏Bootstrap模式?

我已经阅读了这里的帖子,Bootstrap网站,以及Googled就像疯了一样 - 但找不到我确定的答案很简单......

我有一个Bootstrap模式,我从link_to帮助器打开,如下所示:

<%= link_to "New Contact", new_contact_path, {remote: true, 'data-toggle' => 'modal', 'data-target' => "#myModal",  class: "btn btn-primary"} %>
Run Code Online (Sandbox Code Playgroud)

在我的ContactsController.create行动中,我有代码创建Contact然后传递给create.js.erb.在create.js.erb,我有一些错误处理代码(ruby和javascript的混合).如果一切顺利,我想关闭模态.

这是我遇到麻烦的地方.当一切顺利时,我似乎无法解雇模态.

我试过了$('#myModal').modal('hide');,这没有效果.我也试过$('#myModal').hide();,这会导致模态消除但离开背景.

关于如何关闭模态和/或从内部解雇背景的任何指导create.js.erb

编辑

这是myModal的标记:

<div class="modal hide" id="myModal" >
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>Add Contact</h3>
    <div id="errors_notification">
    </div>
  </div>
  <div class="modal-body">
    <%= form_for :contact, url: contacts_path, remote: true do |f| %>  
      <%= f.text_field :first_name, placeholder: "first name" %>
      <%= f.text_field :last_name, placeholder: …
Run Code Online (Sandbox Code Playgroud)

javascript modal-dialog twitter-bootstrap

270
推荐指数
19
解决办法
54万
查看次数

建议让Selenium与Bootstrap模态淡入淡出玩得好吗?

我正在努力以生活方式生活BDD.我正在使用Cucumber(使用Selenium)并且碰巧在我的应用程序中使用Twitter Bootstrap模式.

在运行Cucumber测试时,我遇到了"Selenium::WebDriver::Error::MoveTargetOutOfBoundsError"错误.一番搜索,调试和一般的绝望后,我的结论是,它具有与使用的做"fade"在我的引导模态参数.如果我使用"fade",则抛出错误:

<div class="modal hide fade" id="info-share-edit-modal" style="display: none;">
  .
  .
  .
</div>
Run Code Online (Sandbox Code Playgroud)

如果我删除"fade",那么Selenium充满了快乐,我的测试清晰:

<div class="modal hide" id="info-share-edit-modal" style="display: none;">
  .
  .
  .
</div>
Run Code Online (Sandbox Code Playgroud)

所以,我现在正"fade"从我的各种模态中删除.但是,这让我感到难过,因为我喜欢淡化效果.

有没有其他人使用Selenium在Bootstrap模式中淡入淡出?如果是这样,是否有一些聪明的方法可以使两者很好地协同工作?

顺便说一句(不确定是否重要),我是Rails 3.2.3,Firefox 13.0.1和Ubuntu 12.04LTS.

selenium cucumber ruby-on-rails-3 twitter-bootstrap

13
推荐指数
2
解决办法
4753
查看次数

在rails中动态构建查询

我试图使用ruby on rails复制crunchbase的搜索列表样式.我有一系列过滤器,看起来像这样:

[
   {
      "id":"0",
      "className":"Company",
      "field":"name",
      "operator":"starts with",
      "val":"a"
   },
   {
      "id":"1",
      "className":"Company",
      "field":"hq_city",
      "operator":"equals",
      "val":"Karachi"
   },
   {
      "id":"2",
      "className":"Category",
      "field":"name",
      "operator":"does not include",
      "val":"ECommerce"
   }
]
Run Code Online (Sandbox Code Playgroud)

我将这个json字符串发送到我已经实现了这个逻辑的ruby控制器:

filters = params[:q]
table_names = {}
filters.each do |filter|
    filter = filters[filter]
    className = filter["className"]
    fieldName = filter["field"]
    operator = filter["operator"]
    val = filter["val"]
    if table_names[className].blank? 
        table_names[className] = []
    end
    table_names[className].push({
        fieldName: fieldName,
        operator: operator,
        val: val
    })
end

table_names.each do |k, v|
    i = 0
    where_string = ''
    val_hash …
Run Code Online (Sandbox Code Playgroud)

ruby mysql json ruby-on-rails

12
推荐指数
1
解决办法
1430
查看次数

proxy_association的说明,用于查找无关联的记录

我今天遇到了一些魔法,我希望能帮助你理解它,这样我才能编写有用的代码.

在我的应用程序中,我有三个类:

class Person < ActiveRecord::Base
  has_many :selected_apps
  has_many :app_profiles, through: :selected_apps do
    def unselected(reload=false)
      @unselected_app_profiles = nil if reload
      @unselected_app_profiles ||= proxy_association.owner.app_profile_ids.empty? ?
        AppProfile.all :
        AppProfile.where("id NOT IN (?)", proxy_association.owner.app_profile_ids)
    end
  end
end

class AppProfile < ActiveRecord::Base
end

class SelectedApp < ActiveRecord::Base
  belongs_to :person
  belongs_to :app_profile
end
Run Code Online (Sandbox Code Playgroud)

上面的代码让我可以做到person.app_profiles.unselected并取回AppProfiles当前没有与之相关的所有内容,Person而无需进行大量的SQL工作.辉煌!

我的问题是我不理解代码 - 这总是让我感到不安.我试图通过proxy_association文档,但它是相当不透明的.

任何人都可以提供一个相当直接的解释和/或一个学习更多的好地方吗?

activerecord ruby-on-rails

4
推荐指数
1
解决办法
3985
查看次数

如何使用redirect_to的字符串?

我确信这是一个愚蠢的问题,所以请提前道歉.我想在我的redirect_to中使用一个字符串,如下所示:

class AppStoreController < ApplicationController

  def get_app
    .
    .
    .
    redirect_path_string = "address_book_path"
    redirect_to redirect_path_string
  end

end
Run Code Online (Sandbox Code Playgroud)

(redirect_path_string将使用控制器中的可用变量构造,但我想抽象出这个问题的详细信息.)

当我这样做时,我的浏览器中显示"连接已重置".

有什么想法吗?

redirect ruby-on-rails

2
推荐指数
1
解决办法
2027
查看次数

生产中 wkhtmltopdf-binary gem 的问题

我正在使用 gem 'wicked_pdf' 将 html 转换为 pdf。它在开发模式下运行良好。但是在生产中它被nginx抛出了一个错误。这是生产中的错误日志:

I, [2017-10-17T12:34:09.726920 #17004]  INFO -- : [4a94b9f6-fdf6-4e55-b325-9b3096132d4e] Completed 500 Internal Server Error in 2638ms (ActiveRecord: 30.6ms)
F, [2017-10-17T12:34:09.729566 #17004] FATAL -- : [4a94b9f6-fdf6-4e55-b325-9b3096132d4e]   
F, [2017-10-17T12:34:09.729763 #17004] FATAL -- : [4a94b9f6-fdf6-4e55-b325-9b3096132d4e] RuntimeError (Failed to execute:
["/home/deploy/phoenix/shared/bundle/ruby/2.4.0/bin/wkhtmltopdf", "-q", "file:////tmp/wicked_pdf20171017-17004-ps7ahv.html", "/tmp/wicked_pdf_generated_file20171017-17004-17rkfch.pdf"]
Error: PDF could not be generated!
Command Error: /home/deploy/phoenix/shared/bundle/ruby/2.4.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf_linux_amd64: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory
):
F, [2017-10-17T12:34:09.729900 #17004] FATAL -- : [4a94b9f6-fdf6-4e55-b325-9b3096132d4e]   
F, [2017-10-17T12:34:09.730005 …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails nginx wkhtmltopdf wicked-pdf

1
推荐指数
1
解决办法
1333
查看次数

&lt;ActiveRecord::QueryMethods::WhereChain 在工作范围内出错

我已经成功运行了一段时间的代码,但它刚刚开始抛出错误 - 我们已经改变了数据进入数据库的方式,但相信它更有可能是一个编程问题,或者我已经改变了它错误,但看不到哪里。

该问题似乎是由范围引起的,我们正在运行 Rails 4.2.2

完整的错误是

undefined method `call' for 
 ActiveRecord::QueryMethods::WhereChain:0x007feb8f5c49f0> Did you mean? caller

app/controllers/orders_controller.rb:158:in `weekly_sales_report'
Run Code Online (Sandbox Code Playgroud)

在我的 orders_controller 第 158 行

@sales_this_week_bysales = Order.select("COUNT(order_id) AS nosales, AVG(net_amount) AS avgsale,SUM(sale_cost) AS sale_cost, SUM(net_amount) AS weeklysalestotal, owner_id AS salesman").sales.where.(date_of_sale: (@startdate .. @enddate)).with_salesman.group(:owner_id)
Run Code Online (Sandbox Code Playgroud)

在我的 orders.rb 模型中,我使用了以下范围

scope :with_salesman, -> { joins(:pipe_records).where(pipe_records: {pipe_part_id: 1}).where.not(pipe_records: {owner_id: nil}) }

scope :sales, -> {where ("orders.order_ref <>'' and date_of_sale IS NOT NULL ")}
Run Code Online (Sandbox Code Playgroud)

我将范围重新写入下面,但仍然出现相同的错误

scope :with_salesman, -> { joins(" INNER JOIN pipe_records ON pipe_records.order_id = orders.id …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

0
推荐指数
1
解决办法
975
查看次数