When developing in Rails, we use script/server to run the app, which makes the application available at http://localhost:someport. Later, in production it's usually somedomain.com/. In both cases, the application is mounted at the root of the domain, which means links beginning with / (like say <a href='/users'>Users</a>) which were inadvertently introduced will never break. Then, when someone then deploys your application to a non-root url like mydomain.com/myapp all hell breaks loose and you have a bunch of broken links.
As a preventive measure, it's wiser to both develop and run automated functional test suites (like a Selenium suite) with your application running on a non-root url. That way relative url bugs are caught early enough that nothing significant is affected.
Some ruby servers do indeed support this kind of mounting - but not all, I presume, so script/server does not support it. However, the popular mongrel server does allow this through the --prefix option. We've modified script/server to a more narrow script/mongrel which accepts the --prefix option and always uses mongrel. script/mongrel otherwise behaves like script/server in every respect.
Try it out - you can get it off GitHub from the script-mongrel project. If you're on Windows (or otherwise don't have git), don't worry - it's a single file plus the README. You can simply copy them off the repo browser.
Friday, January 02, 2009
Catching relative url issues in rails early with --prefix
Subscribe to:
Post Comments
(Atom)
Tag Cloud
- .net
- activ
- activeresource
- agile
- ajax
- analysis
- announcement
- anti-pattern
- architecture
- bangalore
- bangpypers
- barcamp
- barcampbangalore4
- barcampbangalore5
- bcb4
- blogger
- book review verdict:read
- books
- browser
- brug
- bug
- call
- cc.rb
- ci
- conference
- content repository
- continuous integration
- cool
- css
- cycle
- darkness
- DCB1
- dcb2
- deployment
- devcampbangalore
- digg
- dining table
- django
- dragdrop
- dzone
- enterprise
- event
- evolving
- feedburner
- feedflare
- feedflareunit
- fun
- functional programming
- GI
- gotcha
- gwt
- hack
- hackdayindia
- howto
- humour
- ide
- india
- innovative
- intellij
- interview
- intro
- irc
- jackrabbit
- java
- javaone
- javascript
- jcr
- jquery
- jruby
- JSNI
- junction
- leisure
- links
- literature
- lucene
- mac
- metaprogramming
- methodology
- microsoft
- mingle
- mochikit
- mongrel
- musings
- mvc
- nasscom
- news
- noob
- OOP
- opinion
- oss
- osx
- performance
- photo
- plugin
- practices
- programming
- prototype
- python
- quality
- quirks
- rails
- rant
- rdt
- recruiting
- recruitment
- refactoring
- registry
- release
- resharper
- REST
- ruby
- rubyconf
- scala
- search
- security
- spawn
- symlinks
- sysinternals
- tdd
- testing
- thoughtworks
- tibco
- tomcat
- tool
- training
- tw
- twb
- tweak
- unconference
- undernet
- utf8
- versioning
- video
- web
- windows
- wrest
- xp
- YUI







2 comments:
This issue is finally resolved in Rails 2.3.2; the option there is --path instead of --prefix, e.g.:
ruby script/server -p 3000 --path=/myapp
Newbie here. What's the solution to the relative bug? I've been wanting to get completely relative paths that don't start with a slash out of the link_to and image_tag helpers but can't figure out how. Thanks.
Post a Comment