Reputation: 2460
I am hosting my Sinatra application using Apache with Passenger. It's hosted within a subfolder -- meaning, my main site is example.com
, my application is at example.com/popcorn
.
So I have a get '/'
route, and that works fine. The problem is that my view includes a HTML form that makes a post request to upload
, and the post '/upload'
route isn't handling it. Instead of example.com/popcorn/upload
, it's trying to get example.com/upload
.
So I figure okay, not the ideal solution, but for now I'll hardcode the form action URL. But that doesn't work either -- making the action popcorn/upload
fails too. This is where I get a little baffled, and my Google-fu was weak, I couldn't find help there.
Maybe I could have some kind of Apache rewrite rule, but is that the correct solution? Am I missing something? I would really appreciate a tip here because it feels like I've messed up something very simple and it's really bugging me.
Upvotes: 1
Views: 195
Reputation: 79733
You probably want the url
helper method. That takes into account where the app is mounted on the server:
url('/upload')
The above code will evaluate to something like this:
http://example.com/popcord/upload
Inside your app you shouldn’t need to change anything, this will be routed to the existing post '/upload'
handler.
Upvotes: 2