2

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?

Andrey Drozdov
  • 571
  • 1
  • 5
  • 22

1 Answers1

4

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

Alejandro Babio
  • 5,189
  • 17
  • 28