How to access Sinatra options in helpers?

How can I access the Sinatra params hash in the user assistant?

eg:.

 # in app/helpers/my_helper.rb module MyApp module MyHelper def self.test () params.inspect end end end # in app.rb helpers MyHelper test_result = test # undefined method `params' for MyApp:Module 
+4
source share
2 answers

You do not need self for helpers:

 module MyApp module MyHelper def test() params.inspect end end end 

Please note that the helper is available only in the context of the request (that is, during the processing of the request):

 get '/' do test_result = test # ... end 
+2
source

Replace params.inspect with params[:inspect] . That should work.

-4
source

All Articles