我在控制器中有以下代码
def search
if params[:name]
response = client.get_games(params[:name])
if response.is_a?(Net::HTTPSuccess)
games = client.parser(response)
unless games.empty?
session[:games] = games
redirect_to game_path(params[:name])
end
end
....
....
....
end
end
I have the following code written in my client
def get_games(name)
find_games(CGI.escape(name))
end
我发现将一些逻辑移动到客户端中的 get_games 方法时遇到了困难。例如,这样做对我不起作用,我想要一些关于如何去做或者我做错了什么的建议
if params[:name]
games = client.get_games(params[:name])
unless games.empty?
session[:games] = games
redirect_to game_path(params[:name])
end
end
...
...
...
end
end
def get_games(name)
response = find_games(CGI.escape(name))
if response.is_a?(NET::HTTPSuccess)
return JSON.parse(response.body)
else
return nil
end
end
前一种情况有效,但后者不起作用。基本上我只需要帮助将代码移动def search
到客户端并且只有redirect_to game_path(params[:name])
在我的控制器中。非常感谢任何帮助