EVE on Rails - Creating an EVE in-game-optimised version of your Rails site
14 February 2008
One thing I love about being a Rails hobbyist is that I can continually think about the best way to do things. With no paycheck hinging on a deliverable, I can refactor continuously until I’m convinced I have the best code I can muster. Sure, I never get anything done, but the exercise makes me a better programmer.
I mentioned previously how to set up an EVE Online-focused rails site. After reading through old Riding Rails posts, I noticed this excellent post on iPhone-optimising your rails project. This process is almost exactly the same for sharing views between EVE and a normal browser. In Rails 2.0 all you have to do is register the MIME Type.
config/initializers/mime_types.rb:
Mime::Type.register_alias "text/html", :eve
Then, in your application controller, use a before_filter to adjust the format as necessary.
app/controllers/application_controller.rb:
before_filter :isolate_eve_browser
private
# EVE-specific data
def isolate_eve_browser
if eve?
request.format = :eve
request_trust unless trusted?
end
end
end
Now everywhere you want to separate your EVE views from your standard browser views, simply use respond_to.
app/controllers/home_controller.rb:
class HomeController < ApplicationController
def index
respond_to do |format|
format.html
format.eve
end
end
end
You can then use app/views/home/index.html.erb and app/views/home/index.eve.erb respectively. This means you can also request trust on the appliaction level instead of on the action level as I mentioned previously. Notice that request_trust method above? It should look something like:
app/controllers/application_controller.rb:
private
def request_trust
response.headers["eve.trustme"] = (
"http://#{request.env['HTTP_HOST']}/" +
"::Your custom message begging for trust."
)
render :template => 'trust_me'
end
The action is rounded out by creating app/views/trustme.eve.erb, which is the template rendered above when the user declines to trust you. Happy coding!
[...] Update: I’ve written up a slightly better way to target the EVE Browser in Rails 2.0. [...]