Hanami, show 'post' controller/view

280 Views Asked by At

I don't understand Hanami, I've created Message model, and I want to pull from DB message by params[:id]. 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])
end

And my erb:

<%= @message.title %>

But it gives me error:

NoMethodError: undefined method `title' for nil:NilClass

What I did wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

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