daemonza
daemonza

Reputation: 527

Passing variable from Sinatra module to view?

I have function in a module in the lib dir of my Sinatra app, that I want to be able to pass a variable back to a view.

Trying to pass it like :

@errorMessage = params["testing error"]
erb :error

Bring the error erb that's in ../views from the lib directory, but does not show the errorMessage var.

erb code :

<p> Error message : <% @errorMessage %></p>  

Anyone have any idea?

Upvotes: 2

Views: 3755

Answers (2)

Samy Dindane
Samy Dindane

Reputation: 18736

It should be <%= @errorMessage %> and not <% @errorMessage %>.

Upvotes: 3

randomuser
randomuser

Reputation: 1898

You can try using :locals

erb :error, :locals => {:errorMessage => "My message"}

And then use errorMessage as a variable inside your template.

Upvotes: 3

Related Questions