Andrey Drozdov Andrey Drozdov - 14 days ago 5x
Ruby Question

Hanami, show 'post' controller/view

I don't understand Hanami, I've created Message model, and I want to pull from DB message by

. The way we do it in Rails
@message = Message.find(params[:id]

I read documentation, and what I did after. My Controller (for show):

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

And my erb:

<%= @message.title %>

But it gives me error:

NoMethodError: undefined method `title' for nil:NilClass

What I did wrong?


At the controller call expose :message, then you can use it in the view or in the template as local variable (without the @).