Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在Rails中实现Google Analytics内容实验_Ruby On Rails_Google Analytics_Content Experiments - Fatal编程技术网

Ruby on rails 如何在Rails中实现Google Analytics内容实验

Ruby on rails 如何在Rails中实现Google Analytics内容实验,ruby-on-rails,google-analytics,content-experiments,Ruby On Rails,Google Analytics,Content Experiments,谷歌分析内容实验需要使用原始URL和变体URL。在Rails中,这是否意味着我们需要创建新的路由和控制器操作?或者,我们可以根据URL参数使用相同的操作来呈现不同的视图吗?我相信您可以将多个路径路由到相同的操作,如: match 'test_ctrl/test_action_1' => 'test_ctrl#test_action', as: :test_action_1 match 'test_ctrl/test_action_2' => 'test_ctrl#test_a

谷歌分析内容实验需要使用原始URL和变体URL。在Rails中,这是否意味着我们需要创建新的路由和控制器操作?或者,我们可以根据URL参数使用相同的操作来呈现不同的视图吗?

我相信您可以将多个路径路由到相同的操作,如:

  match 'test_ctrl/test_action_1' => 'test_ctrl#test_action', as: :test_action_1
  match 'test_ctrl/test_action_2' => 'test_ctrl#test_action', as: :test_action_2
  match 'test_ctrl/test_action_3' => 'test_ctrl#test_action', as: :test_action_3
然后,在TestCtrl控制器内,您可以检查请求数据,并根据请求url呈现特定视图,方法是:

def test_action
  if request.path_info == 'test_ctrl/test_action_1'
    render "/test_action/1"
  elsif request.path_info == 'test_ctrl/test_action_2'
    render "/test_action/2"
  elsif request.path_info == 'test_ctrl/test_action_3'
    render "/test_action/3"
  end
end
只需在视图/测试动作中创建视图1、2和3/