Is it possible to get the value of named route from with in a custom rack app when the app is mounted in rails 3 (in my case a Sinatra app)?
Simply using the route, (login_path) is throwing an exception for an undefined local variable.
UPDATE:
Here is an example, of what I am trying to do:
before do
redirect login_path unless some_condition
end
The app is mounted with
mount App.new, :at => '/path'
This part works as expected.
Thanks, Scott
Controller specific searchUse option -c to search for routes related to controller. Also remember that Rails does case insensitive search. So rails routes -c users is same as rails routes -c Users.
rake routes will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.
Accessing the hosting rails app's routes in the mounted Sinatra might not be very elegant, since the hosted Sinatra should not have knowledge of the app that hosts it.
So instead, it'd better to do this in the rails app.
If you use devise, you can surround your mount block as this:
authenticate "user" do
mount App.new, :at => '/path'
end
This can be done because devise itself is a middleware added before route.
Devise implements this as:
def authenticate(scope)
constraint = lambda do |request|
request.env["warden"].authenticate!(:scope => scope)
end
constraints(constraint) do
yield
end
end
If you don't use devise, you might need to implement something similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With