json = JSON.parse(response.body)
@games = json['machine-games']
paging = json['paging']
if paging
if paging['next']
next_page_query = paging['next'].match(/\?.*/)[0]
@next_page = "/machine_games/search#{next_page_query}"
end
if paging['previous']
previous_page_query = paging['previous'].match(/\?.*/)[0]
@previous_page = "/machine_games/search#{previous_page_query}"
end
end
以上是控制器中 show 方法的一小部分逻辑。我如何将它移动到演示者,以便它保存 machine_games JSON 响应并提供访问游戏和下一页/上一页链接的方法(以及是否它们存在)。{不太熟悉使用演示者模式}