我在rails应用程序上有一个ruby。我在应用程序中添加了一个名为reports的新部分。它没有模型,只有一个控制器和views文件夹中的许多表单。 功能正在按需运行。 我面临的问题是单击提交按钮,登录的用户将自动注销。
我的代码是:
报告控制器:
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
在index.html.haml中:
-set_title "Reports"
-content_for :content_title do
= link_to "Test Case Manager", "/"
»
= "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"
点击提交按钮后,用户登录后会自动退出。请帮帮我。
谢谢, 拉姆亚。
答案 0 :(得分:2)
我有一个类似的问题 - 一个问题是,如果你对Rails应用程序发出POST请求,而你的post请求没有真实性令牌作为其中一个参数,Rails会删除它的会话,通常会导致用户退出。
查看生成表单的HTML源代码 - 它是否包含一个名为真实性令牌的隐藏输入字段?
有几种解决方案,一种是跳过服务器上的检查,但更好的解决方案是将真实性令牌添加到表单中。尝试将其添加到布局HAML文件的head
部分:
= csrf_meta_tag
我认为足以解决您的问题