未初始化的常量" controllername :: modulename" TableauServer

时间:2018-03-29 20:10:40

标签: ruby-on-rails ruby tableau tableau-server

我试图在Ruby on rails上测试tableau_trusted.rb示例以获得对tableau服务器的可信身份验证,但我不断收到错误"未初始化的constantTableauTrustedsController :: TableauTrustedInterface",这是我的代码:

tableautrusteds_controller.rb

class TableauTrustedsController < ApplicationController
  include TableauTrustedInterface

  def index
    tabserver = 'xxxxx'
    tabuser   = 'test'
    tabpath   = 'views/Tableau_DW1/General?:iid=1'
    tabparams = ':embed=yes&:toolbar=no'
    ticket    = tableau_get_trusted_ticket(tabserver, tabuser, request.remote_ip)

    if ticket != "-1"
      url = "http://#{tabserver}/trusted/#{ticket}/#{tabpath}?#{tabparams}"
      redirect_to url
      return
    end

    render :status => 403, :text => "Error with request"
  end
end

module TableauTrustedInterface
  require 'net/http'
  require 'uri'

  # the client_ip parameter isn't necessary to send in the POST unless you have
  # wgserver.extended_trusted_ip_checking enabled (it's disabled by default)
  def tableau_get_trusted_ticket(tabserver, tabuser, client_ip)
    post_data = {
        "username" => tabuser,
        "client_ip" => client_ip
    }

    response = Net::HTTP.post_form(URI.parse("http://#{tabserver}/trusted"), post_data)

    case response
      when Net::HTTPSuccess
        return response.body.to_s
      else
        return "-1"
    end
  end
end

我更改了行&#34;包括TableauTrustedInterface&#34; to&#34;扩展TableauTrustedInterface&#34;但它没有用。 另外,我在浏览器中输入的URL是 http://localhost:3000/tableautrusteds/index,我使用get&quot; tableautrusteds / index&#39;在routes.rb中。 我真的不知道这是否重要,但是有些人问我这个问题。

我对rails有点新意,所以任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:0)

我解决了我的问题,如果有人在这里有类似的问题是我的代码

module TableauTrustedInterfaces
  require 'net/http'
  require 'uri'

  # the client_ip parameter isn't necessary to send in the POST unless you have
  # wgserver.extended_trusted_ip_checking enabled (it's disabled by default)
  def tableau_get_trusted_ticket(tabserver, tabuser, client_ip)
    post_data = {
        "username" => tabuser,
        "client_ip" => client_ip
    }

    response = Net::HTTP.post_form(URI.parse("http://#{tabserver}/trusted"), post_data)

    case response
      when Net::HTTPSuccess
        return response.body.to_s
      else
        return "-1"
    end
  end
end

class TableauTrustedController < ApplicationController
  include TableauTrustedInterfaces

  def index
    tabserver = 'xxxxx'
    tabuser   = 'test'
    tabpath   = 'views/Tableau_DW1/General?:iid=1'
    tabparams = ':embed=yes&:toolbar=no'
    ticket    = tableau_get_trusted_ticket(tabserver, tabuser, request.remote_ip)

    if ticket != "-1"
      url = "http://#{tabserver}/trusted/#{ticket}/#{tabpath}?#{tabparams}"
      redirect_to url
      return
    end
    render json: {}, status: :forbidden
  end
end

为了使用该模块,需要在课前声明。另外,非常重要的是我将文件的名称更改为tableau_trusted_controler.rb,因为rails使用的是蛇形。