Ruby on Rails IGB

From EVEDev

Jump to: navigation, search
Image:Api.pngIn Game Browser Documentation - Category Home - Documentation Home

If using Rails 2 or greater, the following code can handle providing IGB-specific pages from a Rails application and will force the user to trust the website.

# app/controllers/application.rb
  before_filter :igb_detect
  before_filter :igb_trust_required
  private
  def igb_trust_required
    if request.format == :igb
      if request.cgi.env_table['HTTP_EVE_TRUSTED'] != 'yes'
        trust_uri = "http://#{request.env['HTTP_HOST']}/"
        response.headers['eve.trustme'] = "#{trust_uri}::This website requires trust to view."
        return false
      end
    end
    return true
  end

  def igb_detect
    if request.user_agent
      request.format = :igb if request.user_agent.downcase.include? "eve-minibrowser"
    end
    return true
  end
# config/initializers/mime_types.rb
  Mime::Type.register_alias "text/html", :igb

With this you can create view.igb.erb as well as view.html.erb and have the .igb.erb version of the view template served up to IGB users instead of the full-blown version. You can also manually set request.format = :igb if you want to test or provide mobile versions and so on.

Personal tools