




















这是一个创建于 1708 天前的主题,其中的信息可能已经有所发展或是发生改变。
Controller 代码
class CveController < ApplicationController
def index
@cves = Cve.all
end
def show
@cve = Cve.find_by(cve_id: params[:cve_id])
end
end
异常信息
Showing app/views/cve/index.html.erb where line #3 raised:
no implicit conversion of nil into String
Extracted source (around line #3):
<h1>Cve#index</h1>
<p>Find me in app/views/cve/index.html.erb</p>
<% @cves.each do |cve| %>
<tr>
<td><%= cve.cve_id %></td>
<td><%= cve.summary %></td>
Rails.root: /Users/admin/RubyProjects/xx-api
Application Trace | Framework Trace | Full Trace
app/views/cve/index.html.erb:3
Request
Parameters:
None
Toggle session dump
Toggle env dump
Response
Headers:
None
1 agagega 2021 年 10 月 10 日 via iPhone检查这两个字段是否为空 |
6 0c0c0f 2021 年 10 月 10 日 |
7 wangkun025 2021 年 10 月 10 日楼主的写法不大符合 rails 的要求。 还有 find_by 这个,其实一般是用 find(params[:id])的。 还有 cve.cve_id 的话,一般也是 cve.id 。 以上都是 rails 的 [约定优于配置] 的体现。 |
8 0c0c0f 2021 年 10 月 11 日class Cve < ApplicationRecord 这么配置就没问题 注意:如果数据库的 schema 不是 public 就需要在 database.yml 中配置 schema_search_path 中指定 |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。