Rails 如何做静态文件的 URL Rewriting

alex_cheng · October 21, 2014 · Last by Alex_Cheng replied at October 22, 2014 · 1670 hits

有静态文件 graph.html,我希望对于这样的请求"//graph.html;sessionid=",可以得到信息,并且可以返回静态文件 graph.html 的结果,但不希望直接使用 io 操作(即要用 file.read)。

谢谢!

你得到 sessionid 后,谁处理这个 id?

谢谢,我自己昨天晚上搞定了,不过办法不是最好的。

# -*- encoding : utf-8 -*-

class ApplicationController < ActionController::Base
  protected
    def session_handler
      @session_id = params[:sessionid];
      @session = get_session(@session_id)
      if @session
        @session[:id] = @session_id
      else
        render json: {
          code: 0,
          result: {},
          msg: '需要登录。'
        }
      end

      @session
    end
end

route 是这样的

match '/search;jsessionid=:sessionid' => 'data#search'
You need to Sign in before reply, if you don't have an account, please Sign up first.