Ruby on rails Rails-显示的URL与页面加载不同

Ruby on rails Rails-显示的URL与页面加载不同,ruby-on-rails,jquery-mobile,model-view-controller,controller,Ruby On Rails,Jquery Mobile,Model View Controller,Controller,我在rails 3应用程序上使用mobile_detection为移动用户提供单独的页面。我正在通过Safari中的用户代理进行测试。问题是在我的一个进程中,rails向web浏览器URL栏发布的URL与它实际加载的页面不同。因此,如果我刷新页面,它会尝试转到它放在web栏中的错误URL 以下是过程 用户提交参与表格 “参与控制器”保存记录,然后呈现移动版或html版的团队候选人 以下是进程的服务器日志,其中排除了一些详细信息 Started POST "/participations"

我在rails 3应用程序上使用mobile_detection为移动用户提供单独的页面。我正在通过Safari中的用户代理进行测试。问题是在我的一个进程中,rails向web浏览器URL栏发布的URL与它实际加载的页面不同。因此,如果我刷新页面,它会尝试转到它放在web栏中的错误URL

以下是过程

  • 用户提交参与表格
  • “参与控制器”保存记录,然后呈现移动版或html版的团队候选人
  • 以下是进程的服务器日志,其中排除了一些详细信息

        Started POST "/participations" for 127.0.0.1 at 2013-07-20 00:14:37 -0400
        Processing by ParticipationsController#create as HTML
        ...Commits to DB
        Redirected to http://localhost:3000/teams/57/candidate
        Started GET "/teams/57/candidate" for 127.0.0.1 at 2013-07-20 00:14:37 -0400
        Processing by TeamsController#candidate as HTML
        Rendered teams/candidate.mobile.erb within layouts/application (34.9ms)
    
    当我从桌面运行同一进程时,不会发生错误。作为一个夏天的问题:

  • Rails会加载teams/candidate.mobile.erb页面
  • 但是,页面加载后的URL栏将显示/参与
  • 这不会在桌面上发生

    下面是参与者控制器。它的逻辑有些复杂,但本质上是检测记录是否已经创建,并针对该情况和移动设备的情况执行不同的操作

    def创建 @参与=参与。新建(参数[:参与]) @团队=@participation.team

    respond_to do |format|
      if @participation.save
          if mobile_device?
              format.mobile {redirect_to candidate_team_path(@team), notice: 'You have joined the team!'}
          else
              format.html { redirect_to candidate_team_path(@team), notice: 'You have successfully joined the team.' }
          end        
      else
          if @participation.team_id.nil?
              format.mobile { redirect_to :back, notice: 'No team was joined.' }
              format.html { redirect_to :back, notice: 'No team was joined.' }
              format.json { render json: @participation.errors, status: :unprocessable_entity }
          else
              if mobile_device?
                  format.mobile {redirect_to candidate_team_path(@team), notice: 'Welcome back.'}
              else
                  format.html {redirect_to candidate_team_path(@team), notice: 'Welcome back.'}
              end
          end
      end
    end
    

    结束一个伟大的解决方案

    希望这对其他人有帮助。解决方案是在主布局中手动设置URL。考虑到JQM使用页面缓存和内部/外部页面加载的方式,这对于某些页面加载是必需的

    这可以放在application.mobile.erb中

    <div data-role="page" data-url="<% request.fullpath %> "