Reputation: 11202
I create a route for each product from database with following code:
Products.all.each do |product|
get "/#{product.title.latinize}"
end
end
class String
def latinize
self
end
end #or with helpers
which raises NoMethodError: undefined method `latinize' for "hello":String.
How to use helpers (or class's extensions as seen here) from dynamically generated routes in Sinatra?
Upvotes: 1
Views: 113
Reputation: 2912
It's probably because you are defining the latinize
method after you are generating the routes. Move to above the Product.all
section.
Upvotes: 2