Possible to create this redirecting route in Rails?

前端 未结 3 1715
旧巷少年郎
旧巷少年郎 2021-01-30 08:33

Is it possible to do a redirect in the routes file of a Rails app?

Specifically, I\'d like to forward /j/e to /javascripts/embed.js

Rig

3条回答
  •  梦谈多话
    2021-01-30 09:27

    Assuming rails version prior to 3.

    You can create a new RedirectController or tuck a single function away in an existing controller, to do something like the following:

    map.js_embed '/j/e',
        :controller => :redirect_controller,
        :action => :some_function,
        :path => "embed"
    

    Then your function would do this:

    def some_function
      if params[:path]
        redirect_to "/javascripts/#{params[:path]}.js"
      end
    end
    

    or something for that effect.

提交回复
热议问题