小编ren*_*ojf的帖子

如何构建任务'elasticsearch:import:model'

好吧,我安装了elasticsearch-rails gem(版本0.1.5),我可以清楚地看到gem文件中的任务.

但是当我跑步的时候

bundle exec rake environment elasticsearch:import:model CLASS='Comment'
Run Code Online (Sandbox Code Playgroud)

我收到这个错误.

跑步rake environment -D并没有向我展示任务.

elasticsearch正在运行,如果我卷曲http://localhost:9200它会回应我.

为什么这不起作用?

rake ruby-on-rails rake-task elasticsearch

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

Hibernate + SQLite没有创建数据库

这是我的问题:

我有一个使用JavaFX + Hibernate + SQLite的桌面应用程序.这是我的模特:

    @Entity
@Table(name = "usuario")
public class Usuario implements AbstractModel, Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @NotNull @Size(min=5, max=100)
    private String username;

    @NotNull @Size(min=5, max=100)
    private String password;

    @NotNull
    private Boolean administrador;

    @Version
    private Integer version;

    public Usuario() {
    }

    public Usuario(Integer id, String username, String password, Boolean admin, Integer version) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.administrador = admin;
        this.version = version;
    }

    @Override
    public Integer getId() …
Run Code Online (Sandbox Code Playgroud)

java sqlite hibernate javafx

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

elasticsearch-rails空结果

我已经做了Comment.import,它返回0,这意味着在导入过程中没有错误.

我已经做了 Comment.__elasticsearch__.refresh_index!

这是我正在使用的模型:

require "datamapper_adapter"

class Comment
  include DataMapper::Resource

  include Elasticsearch::Model

  property :id, Serial
  property :email, String
  property :author, String
  property :description, String
  property :created_at, DateTime

  belongs_to :picture

  validates_presence_of :email, :author, :description

  settings index: { number_of_shards: 1 } do
    mappings dynamic: 'false' do
      indexes :id, analyzer: 'english', index_options: 'offsets'
      indexes :author, analyzer: 'english', index_options: 'offsets'
      indexes :description, analyzer: 'english', index_options: 'offsets'
    end
  end

  def as_indexed_json(options={})
    as_json.except("picture_id", "created_at", "email", "_persistence_state", "_repository", "_id")
  end
end
Run Code Online (Sandbox Code Playgroud)

而且我对elasticsearch的所有查询都返回一个空数组作为命中.

curl -XPOST 'http://localhost:9200/comments/comment/_search?pretty …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails elasticsearch

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

如何用数据库中的数据填充JavaFX ChoiceBox?

private void initialize() {
    loadPersistenceContext();

    List<Events> events = getEventsChoiceBox(getPersistenceContext());
    ObservableList<Event> data = FXCollections.observableList(events);

    cbEvent.setItems(data); // Inserting data into the ChoiceBox
}
Run Code Online (Sandbox Code Playgroud)

这是我的主要代码。问题是加载表单时,我将对象插入ChoiceBox中而不是属性中。

这是我的列表事件的内容

Object[]
|- String
|- Integer
Object[]
|- String
|- Integer
Run Code Online (Sandbox Code Playgroud)

因此,我想要一个带有该String属性的ChoiceBox并将Integer映射到我的控制器。

我尝试了很多事情,但无法解决。

java javafx

4
推荐指数
2
解决办法
3万
查看次数

试图更新mySQL中的640k行会导致"在查询期间丢失与MySQL服务器的连接"

我正在尝试从seeds.rb文件中执行此行:

ActiveRecord::Base.connection.execute("UPDATE bairros SET created_at = (SELECT NOW());")
Run Code Online (Sandbox Code Playgroud)

我的名为"bairros"的表有643k行,一旦rake db:seed命令到达此文件,就会抛出此错误

    Mysql2::Error: Lost connection to MySQL server during query: UPDATE bairros SET created_at = (SELECT NOW());
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:286:in `query'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:286:in `block in execute'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:286:in `execute'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:220:in `execute'
/home/ubuntu/projetos/AnuncieImoveis/releases/20131015210221/db/seeds.rb:48:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/railties-4.0.0/lib/rails/engine.rb:540:in `load_seed'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:153:in `load_seed'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:181:in `block (2 levels) in <top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/bin/ruby_noexec_wrapper:14:in `eval'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p195@thedoors/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:seed
(See full trace …
Run Code Online (Sandbox Code Playgroud)

mysql ruby-on-rails-4

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

JQuery通过AJAX发布表单不会触发rails respond_to format.js

我有一个简单的表格与param订单.当我的下拉列表发生变化时,我称之为:

$.post("/busca", $("#order_form").serialize(), dataType: "script")
Run Code Online (Sandbox Code Playgroud)

在rails控制器端,我有一个简单format.js的处理ajax调用.事情是,这是行不通的.该js.erb模板从来没有显示.

我的日志显示Processing by BuscaController#index as */*,我不知道它*/*代表什么.有人能帮我吗?

ajax jquery ruby-on-rails-4

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

有没有办法通过两个不同的分隔符拆分Rails中的对象数组?

我想做这样的事情:

@residenciais, @comerciais = TipoImovel.all.split { |t| t.residencial? }
Run Code Online (Sandbox Code Playgroud)

问题是它@comerciais总是空的,因为它永远不会返回对象,因为条件是假的.

有没有更好的方法呢?

ruby ruby-on-rails-4

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