0

我在控制器中有以下代码

def show 

    client = GameAccounts::GameAccountsClient.new 

    ..

    json = client.get_accounts( ..)
    ..
    end

我在 GameAccountsClient 中有以下代码

def get_accounts(..)
      response = query_account(CGI.escape(params[:name])
      JSON.parse(response.body)
    end

我有上面的代码,但我不确定在控制器中调用 get_accounts 方法时如何传递 params[:name]。任何人都可以帮助我在 rails 中传递哈希方法吗?。谢谢

4

1 回答 1

0

如果我理解正确,您只需将其传递params[:name]给您的模型方法。

def show
  client = GameAccounts::GameAccountsClient.new
  json = client.get_accounts(params[:name])
end

def get_accounts(name)
  response = query_account(CGI.escape(name)
  JSON.parse(response.body)
end
于 2013-03-05T17:27:03.790 回答