退出ruby应用程序



我有一个ruby on rails应用程序。我在应用程序中添加了一个名为reports的新部分。它没有模型,只有一个控制器和视图文件夹中的许多表单。功能按预期工作。我面临的问题是,在点击提交按钮时,已登录的用户将自动注销。

我的代码是:

报告控制器:

    class ReportsController < ApplicationController
    def index
    @projects=Project.find(:all)
    @releases=Release.find(:all)
    @cycles=Cycle.find(:all)   
    report_type=params[:report_type]
    if report_type=="1" && params[:cycles]     
    @cycle=Cycle.find(params[:cycles])
    @ics=@cycle.ics     
    puts " report_type===#{report_type}"
    end
    end

    def  update_releases 
     puts "inside releases"
     project = Project.find(params[:project_id]) 
@releases = project.releases
respond_to do |format| 
format.js 
end
end

def update_cycles 
puts "inside update_cycles"
release = Release.find(params[:release_id]) 
@cycles =release.cycles
respond_to do |format| 
format.js    
end 
end 
end

In index.html.haml:

-set_title "Reports"
-content_for :content_title do
  = link_to "Test Case Manager", "/"
  &raquo;
  = "Reports"
%table.grid.full
%tr
    %td.grid.full_panels{:style => "width: 30%"}
      -panel "Reports" do
        = render "reports",:report_type=>params[:report_type]
    %td.grid.full_panels{:style => "width: 70%"}
      -table_panel "Report details" do
        = render "report_details",:report_type=>params[:report_type]
= javascript_include_tag "pages/ic"

_reports.html.haml:

%table.grid.full
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      =link_to 'Test Not Run Per Cycle',reports_path(:report_type=>1)
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Test Cycle Result Comparison',reports_path(:report_type=>2)
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Test Cycle Summary'
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Tester summary per cycle'
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Test Cycle Failure Report'
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Release Test Results Summary'
= javascript_include_tag "pages/ic"

_report_details.html.haml:

-if report_type == "1" 
   = render "tests_not_run_per_cycle",:report_type=>report_type  
   = render "tests_not_run_per_cycle_reports",:report_type=>params[:report_type]

_tests_not_run_per_cycle.html.haml:

-projects=Project.all
-releases = Release.all
-cycles=Release.all
-form_tag reports_path(),:method => :get, :multipart => true  do  
  %table.grid.full_panels
  %tr      
  %td.grid.full_panels{:style => "width: 20%"}
    Project:
  %td.grid.full_panels{:style => "width: 20%"}
    //= select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]),{:onchange => "#{remote_function(:url  => {:action => "update_releases"},:with => "'project_id='+value")}"} 
    = select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]), :class => "update_releases",:include_blank=>true
    //= select_tag 'projects',options_from_collection_for_select(projects, "id", "name"),:'data-remote' => 'true', :'data-url' => 'reports/update_releases', :'data-type' => 'json'  
    =hidden_field_tag "report_type","1"
  %td.grid.full_panels{:style => "width: 20%"}
    Releases:
  %td.grid.full_panels{:style => "width: 20%"}
    <div id="releases">
    = render :partial => 'releases', :object => @releases
  %td.grid.full_panels{:style => "width: 20%"}
    Cycles:
  %td.grid.full_panels{:style => "width: 20%"}
    <div id="cycles">
    = render :partial => 'cycles', :object => @cycles
%tr      
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
    =submit_tag "Submit"
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}      
= javascript_include_tag "pages/ic"

_tests_not_run_per_cycle_reports:

-if report_type=="1" && params[:cycles]
   -ic_to_platform_config = @cycle.ic_platform_configs
   %table
    %th Root
    %th Suite
    %th Case
    %th IC
    %th Executor
    %th Platform
    -@ics.each do |ic|
      %tr
    -ic_model=Ic.find(ic.id)
    - ic_rev=@cycle.get_ic_rev_assign(ic_model)
    - populate_table ic_rev, ic_to_platform_config[ic_model]
 = javascript_include_tag "pages/ic"

在单击提交按钮时,登录的用户将自动注销。请帮我一下。

谢谢,Ramya .

我有一个类似的问题-潜在的问题是,如果您对Rails应用程序进行POST请求,并且您的POST请求没有真实性令牌作为参数之一,Rails会删除其会话,这通常会导致用户注销。

查看生成表单的HTML源代码——它是否包含一个名为真实性令牌的隐藏输入字段?

有几种解决方案,一种是跳过服务器上的检查,但更好的解决方案是将真实性令牌添加到表单中。尝试将其添加到布局HAML文件的head部分:
= csrf_meta_tag

认为这足以解决你的问题

最新更新