这里是Ruby的新手,并试图建立经典的User-Articles MVC结构,而是使用Objectives和Key Results.
问题:
NoMethodError in Home#index - undefined method `keyresults' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
题:
如何在控制器中定义目标和关键结果之间的关系?
我认为这是问题所在.
关于如何进行的任何解释都是惊人的!
我试过了:
@objectives = Objective.all.include(:keyresult)
Run Code Online (Sandbox Code Playgroud)
但那没用.
目标:在索引页面列出所有目标及其相关的关键结果:
目标1
- 关键结果1
- 主要结果3
目标2
- 关键结果2
- 关键结果4
- 关键结果5
objective.rb
class Objective < ApplicationRecord
has_many :objectives_keyresults, dependent: :destroy
has_many :keyresults, through: :objectives_keyresults
Run Code Online (Sandbox Code Playgroud)
keyresult.rb
class Keyresult < ApplicationRecord
belongs_to :objective
Run Code Online (Sandbox Code Playgroud)
home_controller.rb
class HomeController < ApplicationController
def index
@objectives = Objective.all
end
Run Code Online (Sandbox Code Playgroud)
index.html.erb
<%- model_class = Objective -%>
<% @objectives.each do |objective| %>
Objective:
<%= objective.title %>
Key Result:
<% …Run Code Online (Sandbox Code Playgroud) 将新的 rails 应用程序部署到 Heroku 后,我收到了 NoMethodError。在本地一切正常。我不确定如何以及在哪里添加该方法。
我是 ruby 的新手(一般编码),它似乎在 ruby-config 而不是这个特定的应用程序中,但我在将其他应用程序部署到 Heroku 时没有任何问题,所以我想知道配置如何改变.
我已经将 Postgres 和 Redis 添加到 Heroku 并且正在使用 ruby2.6.3和 Rails6.0.0.rc1
错误信息:
/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/base64.rb:59:in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
2019-07-25T08:43:02.237469+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>'
2019-07-25T08:43:02.237508+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:31:in `<main>'
2019-07-25T08:43:02.237532+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2019-07-25T08:43:02.237554+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2019-07-25T08:43:02.237576+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2019-07-25T08:43:02.237614+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2019-07-25T08:43:02.237651+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2019-07-25T08:43:02.237674+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.6/lib/zeitwerk/kernel.rb:16:in `require'
2019-07-25T08:43:02.237696+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in …Run Code Online (Sandbox Code Playgroud) 能否将<%=标签放在标签内<%=,如下所示?
如果没有,它是怎么做的?我已经在表格中找到了图像的名称,并希望在显示图像时在图像路径中使用它。
<%= image_tag("tools/<%= tool.logo %>", :size => "50x50", :class=> "img-circular") %>
Run Code Online (Sandbox Code Playgroud)