小编Mat*_*man的帖子

twitter bootstrap navbar固定顶部重叠站点

我在我的网站上使用bootstrap并且导航栏固定顶部有问题.当我只使用常规导航栏时,一切都很好.但是,当我尝试将其切换到导航栏固定顶部时,网站上的所有其他内容都会向上移动,就像导航栏不在那里而导航栏重叠一样.这基本上是我如何摆脱它:

.navbar.navbar-fixed-top
  .navbar-inner
    .container
.container
  .row
    //yield content
Run Code Online (Sandbox Code Playgroud)

我试图准确复制bootstraps示例,但只有在使用navbar固定顶部时才会出现此问题.我究竟做错了什么?

html twitter-bootstrap

336
推荐指数
13
解决办法
28万
查看次数

如何删除sidekiq中的作业

我在我的rails应用程序中使用sidekiq.我的应用程序的用户创建启动sidekiq作业的报告.但是,有时用户希望能够取消"处理"报告.删除报告很简单,但我也需要能够删除sidekiq作业.

到目前为止,我已经能够获得这样的工人列表:

workers = Sidekiq::Workers.new
Run Code Online (Sandbox Code Playgroud)

并且每个worker都有包含report_id的args,因此我可以识别哪个作业属于哪个报告.但是,我不确定如何实际删除该作业.应该注意的是,我想删除作业当前是忙还是重试.

ruby-on-rails sidekiq

36
推荐指数
5
解决办法
4万
查看次数

如何在用户提交无效输入后重新加载google recaptcha小部件

我有一个注册表单,上面有新的google recaptcha小部件.当用户提交信息时,我们使用javascript检查验证并将问题返回到页面(例如:"请使用有效的电话号码").但是,由于页面没有重新加载,当用户输入正确的信息并再次提交时(无需再次进行重新记录)... recaptcha不再有效,他们无法在不重新加载页面的情况下提交.

有一个很好的解决方案吗?我可以以某种方式重新加载小部件吗?我试过grecaptcha.render,但它并没有真正做任何事情.

编辑:

当我尝试再次渲染窗口小部件时,它说"占位符元素必须为空"

我试着清空似乎有用的元素($('.g-recaptcha').empty();)然后渲染但它仍然抛出相同的错误.

javascript ruby-on-rails recaptcha

31
推荐指数
5
解决办法
7万
查看次数

Twilio说我没有权限发送到我的'To'号码区域

我正在尝试发送简单的短信,并且已经使用我的应用程序这样做了一年多.突然间,在我的舞台和当地环境(刺激很好),我不断收到这个错误:

Twilio::REST::RequestError: Permission to send an SMS has not been enabled for the region indicated by the 'To' number: '+13105551234'
Run Code Online (Sandbox Code Playgroud)

这两个数字都是加利福尼亚当地的数字,我的帐户已启用美国.我将此SOF帖子的号码更改为5551234,但它们都是有效号码(来自号码是我的twilio号码,而号码是我的个人手机号码.

client.account.messages.create(body: 'hello', to: '+13105551234', from: '+15105551234')
Run Code Online (Sandbox Code Playgroud)

可能导致此错误的原因是什么?

编辑:我应该提一下,当我发送短信到我朋友的电话时工作,然后当我第二次尝试他的号码时,它给了我同样的错误.

ruby-on-rails twilio

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

Arel + Rails 4.2导致问题(绑定丢失)

我们最近从Rails 4.1升级到Rails 4.2,并且发现使用Arel + Activerecord时出现问题,因为我们遇到了这种类型的错误:

ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 0 parameters, but prepared statement "" requires 8
Run Code Online (Sandbox Code Playgroud)

这是破坏的代码:

customers = Customer.arel_table

      ne_subquery = ImportLog.where(
        importable_type: Customer.to_s,
        importable_id: customers['id'],
        remote_type: remote_type.to_s.singularize,
        destination: 'hello'
      ).exists.not

      first  = Customer.where(ne_subquery).where(company_id: @company.id)
      second = Customer.joins(:import_logs).merge(
        ImportLog.where(
          importable_type: Customer.to_s,
          importable_id: customers['id'],
          remote_type: remote_type.to_s.singularize,
          status: 'pending',
          destination: 'hello',
          remote_id: nil
        )
      ).where(company_id: @company.id)

      Customer.from(
        customers.create_table_alias(
          first.union(second),
          Customer.table_name
        )
      )
Run Code Online (Sandbox Code Playgroud)

我们想出了如何通过将exists.not移动到Customer.where中来解决查询的第一部分(运行到没有绑定的相同rails错误),如下所示:

ne_subquery = ImportLog.where(
       importable_type: Customer.to_s,
       importable_id: customers['id'],
       destination: 'hello'
     )

     first  = Customer.where("NOT (EXISTS (#{ne_subquery.to_sql}))").where(company_id: …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails arel

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

在nil对象上使用strftime - 如何防止错误?

我使用strftime将原始时间格式化为输入框的文本.通常,当我使用strftime时,我检查对象是否为nil以防止错误,除非使用nil?但是我似乎不能在这里使用它:

<%= text_field_tag :event_date, @event.event_date.strftime("%m/%d/%Y at %I:%M%p"), :size=>30 %>
Run Code Online (Sandbox Code Playgroud)

我删除了,因为它抛出了一个错误.如果@ event.event_date为nil,如何确保此语句有效?

谢谢

ruby-on-rails strftime

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

设计更改密码不起作用(未知属性:current_password)

我不太确定我做错了什么,但当用户尝试在我的应用上更改密码时,它会给出一个错误,即current_password是一个未知属性.

这是我的代码:

def configure_devise_permitted_parameters
  registration_params = [:email, :password, :password_confirmation, :first_name, :last_name]

  if params[:action] == 'update'
    devise_parameter_sanitizer.for(:user_update) {
      |u| u.permit(registration_params << :current_password)
    }
  elsif params[:action] == 'create'
    devise_parameter_sanitizer.for(:sign_up) {
      |u| u.permit(registration_params)
    }
  end
end

class RegistrationsController < Devise::RegistrationsController
  def update
    account_update_params = devise_parameter_sanitizer.sanitize(:user_update)

    if account_update_params[:password].blank?
      account_update_params.delete("password")
      account_update_params.delete("password_confirmation")
      account_update_params.delete("current_password")
    end

    @user = User.find(current_user.id)
    if @user.update_attributes(account_update_params)
      set_flash_message :notice, :updated
      sign_in @user, bypass: true
      redirect_to after_update_path_for(@user)
    else
      render "edit"
    end
  end
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?在正确保存新密码之前,我应该使用current_password检查它是否正确?

编辑:堆栈跟踪

activerecord (4.0.3) lib/active_record/attribute_assignment.rb:47:in `rescue in _assign_attribute'
activerecord (4.0.3) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise

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

Rspec验证失败 - 属性不能为空,但不是空白

我刚刚编写了一个测试,用于测试新用户创建是否也包含管理设置.这是测试:

describe User do

  before(:each) do
    @attr = { 
      :name => "Example User", 
      :email => "user@example.com",
      :admin => "f"
    }
  end

  it "should create a new instance given valid attributes" do
    User.create!(@attr)
  end

  it "should require a name" do
    no_name_user = User.new(@attr.merge(:name => ""))
    no_name_user.should_not be_valid
  end

  it "should require an email" do
    no_email_user = User.new(@attr.merge(:email => ""))
    no_email_user.should_not be_valid
  end

  it "should require an admin setting" do
    no_admin_user = User.new(@attr.merge(:admin => ""))
    no_admin_user.should_not be_valid
  end

end
Run Code Online (Sandbox Code Playgroud)

然后,在我的用户模型中,我有:

class User …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails

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

嵌套资源路由助手无法正常工作

我有一个像这样的嵌套路线:

  resources :apps do
    resources :issues
  end
Run Code Online (Sandbox Code Playgroud)

查看与应用程序相关的所有问题的帮助程序如下:

app_issues_url(app)
Run Code Online (Sandbox Code Playgroud)

但现在我想使用帮助器指向特定应用程序的特定问题,如apps/1/issues/1,但我不知道如何使用该帮助程序.这个网址的帮手是什么?

routes ruby-on-rails

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

如何在rails控制器中使用Google Analytics自定义事件?

我想要做的是在我的控制器中使用谷歌分析的自定义事件跟踪,逻辑完成.我不太确定如何将javascript代码放入我的控制器中,或者根本不可能.我如何在我的控制器中放置这样的东西:

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
Run Code Online (Sandbox Code Playgroud)

要么

_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
Run Code Online (Sandbox Code Playgroud)

谢谢!我应该使用哪一个?编辑:

以下是我根据建议进行设置的方法:

跟踪代码部分:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-ACCOUNT']);
  _gaq.push(['_setDomainName', 'sitename.com']);
  _gaq.push(['_trackPageview']);
  <%= render "layouts/ga_events" %>

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
Run Code Online (Sandbox Code Playgroud)

_ga_events.html.erb(我在"value"参数中添加了)

<% unless session[:events].nil? %>
  <% session[:events].each do |event|%>
     _gaq.push(['_trackEvent', '<%= event[:category]%>', '<%= event[:action]%>', '<%= …
Run Code Online (Sandbox Code Playgroud)

javascript google-analytics ruby-on-rails

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