2

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?

4

2 回答 2

3

您可以尝试使用 :locals

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

然后在模板中使用 errorMessage 作为变量。

于 2012-05-11T08:39:00.800 回答
3

它应该是<%= @errorMessage %>而不是<% @errorMessage %>

于 2012-05-11T14:32:57.887 回答