gpt4 book ai didi

ruby - Hanami,显示 'post' Controller / View

转载 作者:数据小太阳 更新时间:2023-10-29 08:36:00 24 4
gpt4 key购买 nike

我不明白 Hanami,我已经创建了消息模型,我想通过 params[:id] 从数据库消息中提取。我们在 Rails 中的做法 @message = Message.find(params[:id].

我阅读文档,然后我做了什么。我的 Controller (用于展示):

def call(params)
@message = MessageRepository.find(params[:id])
end

还有我的错误:

<%= @message.title %>

但它给了我错误:

NoMethodError: undefined method `title' for nil:NilClass

我做错了什么?

最佳答案

在 Controller 调用expose :message,然后你可以在 View 或模板中使用它作为局部变量(没有@)。

关于ruby - Hanami,显示 'post' Controller / View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39943159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com