小编tfa*_*ina的帖子

盆景:使用create_index!或者:force选项来创建它

在过去的4周里,我一直在与Bonsai和Elasticsearch进行一场激烈的战斗,这在某种程度上令人沮丧,因为几个月前我让它在另一个应用程序上工作.
我的应用程序崩溃了,当我去Heroku时,我得到了"应用程序错误"警告.当我结账时,Herkou Logs我发现了一些我认为是问题的东西:

2016-08-31T23:23:47.189996+00:00 heroku[web.1]: Process exited with status 1
2016-09-01T00:12:50.088164+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-01T00:12:57.130922+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 14657 -e production`
2016-09-01T00:13:00.947244+00:00 app[web.1]: => Booting WEBrick
2016-09-01T00:13:00.947263+00:00 app[web.1]: => Rails 4.2.5.1 application starting in production on http://0.0.0.0:14657
2016-09-01T00:13:00.947264+00:00 app[web.1]: => Run `rails server -h` for more startup options
2016-09-01T00:13:00.947265+00:00 app[web.1]: => Ctrl-C to shutdown server
2016-09-01T00:13:00.947266+00:00 app[web.1]: Exiting
2016-09-01T00:13:00.947281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/elasticsearch-model-0.1.9/lib/elasticsearch/model/importing.rb:118:in `import': professors does not exist to be imported …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku

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

Hotwire Turbo 流返回头部:no_content

我有一个包含帖子和评论的系统,每个Post has_many Comment都是。我正在尝试设置一个涡轮流,以便当您发表评论时它会立即显示。

\n

一切正常,数据被保存到数据库中,但涡轮流似乎没有正确返回。当我点击“评论”按钮时,没有任何变化,我收到一条:no_content消息CommentsController#create

\n
  \xe2\x86\xb3 app/controllers/comments_controller.rb:11:in `create'\n[ActiveJob] Enqueued Turbo::Streams::ActionBroadcastJob (Job ID: b0be3a08-d7bb-4216-aac5-2f274a22dcbf) to Async(default) with arguments: "Z2lkOi8vY2lhby9Qb3N0LzM", {:action=>:append, :target=>"comments", :locals=>{:comment=>#<GlobalID:0x00007fa94123baf8 @uri=#<URI::GID gid://ciao/Comment/16>>}, :partial=>"comments/comment"}\n[ActiveJob] Enqueued Turbo::Streams::ActionBroadcastJob (Job ID: 382e45b4-7a8f-4c8c-9e48-819fab0c19c4) to Async(default) with arguments: "Z2lkOi8vY2lhby9Qb3N0LzM", {:action=>:replace, :target=>#<GlobalID:0x00007fa9401ea938 @uri=#<URI::GID gid://ciao/Comment/16>>, :locals=>{:comment=>#<GlobalID:0x00007fa9401ea0f0 @uri=#<URI::GID gid://ciao/Comment/16>>}, :partial=>"comments/comment"}\nNo template found for CommentsController#create, rendering head :no_content\nCompleted 204 No Content in 37ms (ActiveRecord: 8.5ms | Allocations: 8931)\n\n
Run Code Online (Sandbox Code Playgroud)\n

Turbo 似乎可以在数据库中创建评论,并发送回评论 POST 请求,我可以在浏览器网络选项卡中看到该请求。我想知道为什么会出现:no_content以及为什么评论在页面刷新之前不会显示。

\n

Place.rb

\n
class Post < ApplicationRecord\n  belongs_to …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails hotwire-rails turbo

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

刺激控制器动作发射两次

我是 StimulusJS 的新手,我只想在用户添加新帖子时显示附加在其他帖子后面的帖子内容。一切似乎都有效,但帖子被附加了两次,因此看起来表单已提交了两次。

  <div data-controller="posts">
     <div data-target="posts.add">
     </div>
     <!-- this is from a rails partial but it's all inside the data-controller -->
     <%= form_with scope: :post, url: posts_path, method: 'post', data: { action: "post#addBody" } do |form| %>
     <%= form.text_field :content, class: "form-control", data: { target: "posts.body"} %>
     <%= form.submit class: "btn btn-primary" %>
  </div>
Run Code Online (Sandbox Code Playgroud)

实际控制人:

import { Controller } from "stimulus"

export default class extends Controller {
  static targets = ["body", "add"]

  addBody() {
    let content = this.bodyTarget.value;
    this.addTarget.insertAdjacentHTML('beforebegin', …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails stimulusjs

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

由于验证码导致Rails服务器崩溃?

在周末我关闭了我的本地主机服务器因为我没有做任何事情.然而本周我有很多问题需要重新启动它.我与rmagick的第一个问题,我不得不安装(?)或更新命令行工具,重新安装rmagick和nokogiri.

现在这个问题似乎已经落后于我,但每次我都跑了 rails s

它在启动后兑现,我收到此错误:

 => Booting WEBrick
=> Rails 4.2.5.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/tfantina/Documents/Code and Websites/Ruby & Rails Stuff/professor/config/initializers/recaptcha.rb:11:in `block in <top (required)>': undefined method `public_key=' for #<Recaptcha::Configuration:0x007fbaa89d09d0> (NoMethodError)
Did you mean?  public_send
    from /Users/tfantina/.rvm/gems/ruby-2.3.1/gems/recaptcha-4.0.0/lib/recaptcha.rb:30:in `configure'
    from /Users/tfantina/Documents/Code and Websites/Ruby & Rails Stuff/professor/config/initializers/recaptcha.rb:10:in `<top (required)>'
    from /Users/tfantina/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'
    from /Users/tfantina/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/tfantina/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/tfantina/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'
    from /Users/tfantina/.rvm/gems/ruby-2.3.1/gems/railties-4.2.5.1/lib/rails/engine.rb:652:in …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-4

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

在JavaScript中复制字符串

是否可以在剪贴板中放置变量?我看过很多文章都是通过选择DOM元素中存在的文本然后复制它来完成此操作的,这很简单,但是我没有看到复制DOM中没有的内容的文章。
我想要一个包含字符串的变量或常量,然后将其发送到剪贴板,而使其不会出现在浏览器窗口中(甚至是隐藏元素)。我知道使用隐藏元素将是解决此问题的快速方法,但是如果有更简洁的方法,它会显得有些笨拙。

javascript

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

在 Rails 中建立关联的问题

我有一个 Post 模型和一个 User 模型。用户可以喜欢帖子,此信息保存在单独的 Love 模型中,而不是直接保存在帖子上,因为用户必须能够看到他们喜欢的帖子的记录。

我有这样的迁移:

    create_table :loves do |t|
      t.references :post, null: false, foreign_key: true
      t.references :user, null: false, foreign_key: true
    end
Run Code Online (Sandbox Code Playgroud)

用户名

  has_many :loves
Run Code Online (Sandbox Code Playgroud)

后.rb

  has_many :loves
Run Code Online (Sandbox Code Playgroud)

爱情.rb

class Love < ApplicationRecord
  belongs_to :user
  has_one :dinner
end

Run Code Online (Sandbox Code Playgroud)

这个关联似乎不起作用,每当我尝试喜欢一个帖子时,我都会收到这个错误:

uninitialized constant User::Lofe 
Run Code Online (Sandbox Code Playgroud)

我意识到“Lofe”这个词可能看起来像是 Love 的拼写错误,这就是我的想法,但我已经搜索了整个代码库,但没有Lofe.

在 Rails 控制台中,如果我输入,User.first.love我会得到一个错误,表明Did you mean? loves这似乎表明关联存在(适用于用户和晚餐),但如果我输入User.first.loves它会抛出相同的未初始化常量错误。

activerecord ruby-on-rails

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