小编Sim*_*mon的帖子

安装debugger-linecache时出错:错误:无法构建gem原生扩展

我试图捆绑安装,但它显示上述错误或调试程序..请从终端找到详细的错误

Installing debugger-linecache (1.1.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/ruby/bin/ruby extconf.rb
checking for vm_core.h... no
checking for vm_core.h... no
Makefile creation failed
************************************************************************** 
No source for ruby-1.9.2-p0 provided with debugger-ruby_core_source gem.
**************************************************************************
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog …
Run Code Online (Sandbox Code Playgroud)

ruby-1.9.2 ruby-on-rails-3.1

16
推荐指数
3
解决办法
1万
查看次数

Textarea调整大小并触发best_in_place模糊事件

我在几个textareas上使用best_in_place gem,有时(看似随机)textarea'jumps'并在我点击save时触发blur事件,提示"放弃你的更改"警告.

这是代码:

<p>Administrator Notes (<%= link_to 'Edit', '#', id: 'edit_notes_link', onclick: 'event.preventDefault()' %>)</p>
<div class="panel radius">
  <%= best_in_place [:admin, @booking], :notes, type: :textarea, ok_button: 'Save', cancel_button: 'Cancel', activator: '#edit_notes_link', display_with: :simple_format, nil: '<i>None</i>' %>
</div>
Run Code Online (Sandbox Code Playgroud)

这是行为的GIF:

http://f.cl.ly/items/1q0o0x2G111P012b131z/output_optimized.gif

(以及GIF拍摄的视频)

我猜测某些地方有一些JavaScript欺骗,但我不知道从哪里开始调试它.如果您已经看到Best in Place表现得像这样,或者您有一些指导如何调试它,那么我真的很感激一些帮助.

javascript ruby-on-rails ruby-on-rails-3.2 best-in-place

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

弹性搜索,轮胎和协会

运行:Ruby 1.9.3p0(2011-10-30修订版33570)[x86_64-darwin11.2.0],Rails 3.2.0

我正试图通过各种协会的TIRE宝石进行弹性搜索.出于某种原因,我在TIRE导入或偶尔在视图上执行rake时不断收到以下错误/错误:

Daves-MacBook-Pro:outdoor dave$ rake environment tire:import CLASS=Gear FORCE=true
[IMPORT] Deleting index 'gears'
[IMPORT] Creating index 'gears' with mapping:
{"gear":{"properties":{}}}
[IMPORT] Starting import for the 'Gear' class
--------------------------------------------------------------------------------
101/101 | 100% rake aborted!######################################
undefined method `last_name' for nil:NilClass

Tasks: TOP => tire:import
Run Code Online (Sandbox Code Playgroud)

这是我的模型: GEAR

class Gear < ActiveRecord::Base
  attr_accessible :title, :size, :price, :image_url, :sub_category_id, :user_id
  belongs_to :user
  belongs_to :sub_category

  validates :title, presence: true
  validates :size,  presence: true
  validates :price, presence: true
  validates :sub_category_id, presence: true
  validates :user_id, presence: …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails associations elasticsearch tire

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

使用Sunspot查询具有不同属性的多个模型

我正在使用Sunspot来索引和搜索Rails项目中的几个模型,我需要根据模型与模型的HABTM关联来限制结果Department.这是因为用户可能没有权限查看所有部门的记录,因此不应返回这些部门的结果.

以下是两个模型的重要部分:

class Message < ActiveRecord::Base
  has_many :comments, dependent: :destroy
  has_and_belongs_to_many :departments

  searchable do
    text :title, :body
    text :comments do
      comments.map(&:body)
    end
    date :created_at
    integer :department_ids, using: :department_ids, references: Department, multiple: true
  end
end

class Document < ActiveRecord::Base
  has_and_belongs_to_many :departments

  searchable do
    text :name
    date :created_at
    integer :department_ids, using: :department_ids, references: Department, multiple: true
  end
end
Run Code Online (Sandbox Code Playgroud)

这是搜索控制器代码:

class SearchController < ApplicationController
  def index
    # These arrays are created here for the sake of this example
    document_permitted_departments = [1, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails sunspot sunspot-rails sunspot-solr

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

如何构建此Rails/PostgreSQL查询以基于模型子项的属性返回模型的实例?

我正在开发一个应用程序,其中User有许多项目,并且Project有很多角色.Role有一个布尔filled属性来指示某人何时接受了该角色.

我想构建一个查询,它返回所有没有角色或具有已经填充的角色的项目.这是我到目前为止最接近的:

@user.projects.includes(:roles).where("roles.id IS NULL OR roles.filled IS TRUE").references(:roles)
Run Code Online (Sandbox Code Playgroud)

问题是roles.filled IS TRUE查询的一部分是匹配具有填充和未填充角色的项目.我需要这个只匹配所有角色都填充的项目.

搜索PostgreSQL文档,它看起来bool_and可能是要走的路,但我的SQL技能不是很好,我还没有设法让它工作.

我意识到我可以轻松地使用select或者这样做reject但我想通过查询数据库来保持它的效率.

有人可以提供一些建议吗?

更新:(简化)模型及其关系:

应用程序/模型/ user.rb

class User < ActiveRecord::Base
  has_many :projects
end
Run Code Online (Sandbox Code Playgroud)

应用程序/模型/ project.rb

class Project < ActiveRecord::Base
  belongs_to :user
  has_many :roles
end
Run Code Online (Sandbox Code Playgroud)

应用程序/模型/ role.rb

class Role < ActiveRecord::Base
  belongs_to :project

  # `filled` is a boolean attribute with a default value of false
end
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails

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

从 Rails 应用程序调用 API 时,应将令牌存储在哪里?

我正在编写一个库来调用第三方 API,以便 Rails 应用程序可以使用它。为了进行身份验证,API 最初使用基本身份验证来返回用于所有其他请求的令牌。令牌的有效期为 1 小时,并且可以使用相同的基本身份验证凭据获取多个令牌,而不会使任何其他令牌失效。

这是我到目前为止所拥有的精简版本:

# frozen_string_literal: true

require "rest-client"

class AcmeClient
  ACME_API_URL = Application.secrets.acme[:url]
  ACME_API_KEY = Application.secrets.acme[:key]
  ACME_API_SECRET = Application.secrets.acme[:secret]

  def health_check
    url = ACME_API_URL + "api/health"
    token = fetch_token
    RestClient.get url, { Authorization: "Bearer #{token}"}
  end

  private

  def fetch_token
    url = ACME_API_URL + "/api/token"
    response = RestClient::Request.execute(
      method: :post,
      url: url,
      user: ACME_API_KEY,
      password: ACME_API_SECRET,
      payload: "grant_type=client_credentials"
    )
    JSON.parse(response.body)["access_token"]
  end
end
Run Code Online (Sandbox Code Playgroud)

我已将该health_check方法作为可用 API 端点的示例。

之前只使用现有的 gem 来调用 API,我不确定如何处理返回的令牌。我不想在每次 API 调用之前获取一个新的,因为这似乎不必要地过多,所以我猜将它存储在某个地方是有意义的。

在这种情况下,是否最好创建一个acme_tokens包含 …

ruby ruby-on-rails rest-client

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