简体   繁体   English

在Rails中的方法中传递参数Hash

[英]Passing params Hash in methods in rails

I have the following code in the controller 我在控制器中有以下代码

def show 

    client = GameAccounts::GameAccountsClient.new 

    ..

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

I have the following code in GameAccountsClient 我在GameAccountsClient中有以下代码

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

I have the above code and i am not sure how to pass params[:name] while calling the get_accounts method in the controller. 我有上面的代码,我不确定在控制器中调用get_accounts方法时如何传递params [:name]。 Can anyone help me out with passing the hash's in methods in rails ? 任何人都可以通过rails中的hash方法来帮助我吗? .Thank you 。谢谢

If i understand it correctly, you just need to pass the params[:name] to your model method. 如果我正确理解,则只需将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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM