Andrey Drozdov Andrey Drozdov - 1 year ago 80
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download